class Weapon:
    def __init__(self, config):
        self.name = config.get('Weapon', 'Name')
        self.damage = config.getint('Weapon', 'Damage')
        self.fire_rate = config.getfloat('Weapon', 'FireRate')
        self.range = config.getint('Weapon', 'Range')
        self.ammo = config.getint('Weapon', 'Ammo')
        self.lock_on = config.getboolean('Weapon', 'LockOn')
        self.lock_on_range = config.getint('Weapon', 'LockOnRange')
        self.lock_on_speed = config.getint('Weapon', 'LockOnSpeed')
        self.target = None

    def fire(self):
        if self.ammo > 0:
            if self.lock_on and self.target:
                # 射击目标
                print(f"Firing at {self.target.name} with {self.name}")
                self.target.health -= self.damage
                self.ammo -= 1
            else:
                # 射击方向
                print(f"Firing in direction with {self.name}")
                self.ammo -= 1

    def lock_on_target(self, target):
        if self.lock_on and target.distance <= self.lock_on_range:
            self.target = target
            print(f"Locking on to {target.name}")
        else:
            self.target = None
            print("No target to lock on")

class Enemy:
    def __init__(self, name, position):
        self.name = name
        self.position = position
        self.health = 100

    @property
    def distance(self):
        # 计算与玩家的距离
        return ((self.position[0] - player_position[0]) ** 2 + (self.position[1] - player_position[1]) ** 2) ** 0.5

# 示例使用
config = configparser.ConfigParser()
config.read('weapon_config.ini')
weapon = Weapon(config)

enemy1 = Enemy("Enemy1", (100, 100))
enemy2 = Enemy("Enemy2", (200, 200))

player_position = (0, 0)

weapon.lock_on_target(enemy1)
weapon.fire()