示例#1
0
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1));
         if (num.Internal < 0)
         {
             queue.HandleError(entry, "Must provide a non-negative number!");
             return;
         }
         EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));
         if (entity == null)
         {
             queue.HandleError(entry, "Invalid entity!");
             return;
         }
         PlayerTag player;
         if (entity.TryGetPlayer(out player))
         {
             UFMHealthController healthController = player.Internal.player.gameObject.GetComponent <UFMHealthController>();
             uint amount = (uint)num.Internal;
             if (healthController != null)
             {
                 healthController.Heal(amount);
                 amount = (uint)(((double)amount / healthController.maxHealth) * 100.0);
             }
             PlayerLife life = player.Internal.player.life;
             life._health = healthController.Translate();
             life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
             {
                 life.health
             });
             if (entry.ShouldShowGood(queue))
             {
                 uint finalHealth = healthController != null ? healthController.health : life.health;
                 entry.Good(queue, "Successfully healed a player to a new health value of " + finalHealth + "!");
             }
             return;
         }
         ZombieTag zombie;
         if (entity.TryGetZombie(out zombie))
         {
             Zombie inZomb = zombie.Internal;
             inZomb.health += (ushort)num.Internal;
             if (inZomb.health > inZomb.maxHealth)
             {
                 inZomb.health = inZomb.maxHealth;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a zombie to a new health value of " + inZomb.health + "!");
             }
             return;
         }
         AnimalTag animal;
         if (entity.TryGetAnimal(out animal))
         {
             Animal inAnimal = animal.Internal;
             inAnimal.health += (ushort)num.Internal;
             if (inAnimal.health > inAnimal.asset.health)
             {
                 inAnimal.health = inAnimal.asset.health;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed an animal to a new health value of " + inAnimal.health + "!");
             }
             return;
         }
         BarricadeTag barricade;
         if (entity.TryGetBarricade(out barricade))
         {
             Barricade inBarricade = barricade.InternalData.barricade;
             inBarricade.health += (ushort)num.Internal;
             ushort max = ((ItemBarricadeAsset)Assets.find(EAssetType.ITEM, inBarricade.id)).health;
             if (inBarricade.health > max)
             {
                 inBarricade.health = max;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a barricade to a new health value of " + inBarricade.health + "!");
             }
             return;
         }
         ResourceTag resource;
         if (entity.TryGetResource(out resource))
         {
             ResourceSpawnpoint inResource = resource.Internal;
             inResource.health += (ushort)num.Internal;
             ushort max = ((ResourceAsset)Assets.find(EAssetType.RESOURCE, inResource.id)).health;
             if (inResource.health > max)
             {
                 inResource.health = max;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a resource to a new health value of " + inResource.health + "!");
             }
             return;
         }
         StructureTag structure;
         if (entity.TryGetStructure(out structure))
         {
             Structure inStructure = structure.InternalData.structure;
             inStructure.health += (ushort)num.Internal;
             ushort max = ((ItemStructureAsset)Assets.find(EAssetType.ITEM, inStructure.id)).health;
             if (inStructure.health > max)
             {
                 inStructure.health = max;
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a structure to a new health value of " + inStructure.health + "!");
             }
             return;
         }
         VehicleTag vehicle;
         if (entity.TryGetVehicle(out vehicle))
         {
             vehicle.Internal.askRepair((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully healed a vehicle to a new health value of " + vehicle.Internal.health + "!");
             }
             return;
         }
         queue.HandleError(entry, "That entity can't be healed!");
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, ("Failed to heal entity: " + ex.ToString()));
     }
 }
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));

            if (entity == null)
            {
                queue.HandleError(entry, "Invalid entity!");
                return;
            }
            EPlayerKill kill; // for use with "out EPlayerKill" parameters
            PlayerTag   player;

            if (entity.TryGetPlayer(out player))
            {
                PlayerLife life = player.Internal.player.life;
                life.askDamage(life.health, Vector3.zero, EDeathCause.KILL, ELimb.SPINE, CSteamID.Nil, out kill, null);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully killed a player!");
                }
                return;
            }
            ZombieTag zombie;

            if (entity.TryGetZombie(out zombie))
            {
                while (!zombie.Internal.isDead)
                {
                    uint xp;
                    zombie.Internal.askDamage((byte)zombie.Internal.health, Vector3.zero, out kill, out xp);
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully killed a zombie!");
                }
                return;
            }
            AnimalTag animal;

            if (entity.TryGetAnimal(out animal))
            {
                while (!animal.Internal.isDead)
                {
                    uint xp;
                    animal.Internal.askDamage((byte)animal.Internal.health, Vector3.zero, out kill, out xp);
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully killed an animal!");
                }
                return;
            }
            BarricadeTag barricade;

            if (entity.TryGetBarricade(out barricade))
            {
                // TODO: Use BarricadeManager?
                barricade.InternalData.barricade.askDamage(barricade.InternalData.barricade.health);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully destroyed a barricade!");
                }
                return;
            }
            ResourceTag resource;

            if (entity.TryGetResource(out resource))
            {
                // TODO: Use ResourceManager?
                resource.Internal.askDamage(resource.Internal.health);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully destroyed a resource!");
                }
                return;
            }
            StructureTag structure;

            if (entity.TryGetStructure(out structure))
            {
                // TODO: Use StructureManager?
                structure.InternalData.structure.askDamage(structure.InternalData.structure.health);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully destroyed a structure!");
                }
                return;
            }
            VehicleTag vehicle;

            if (entity.TryGetVehicle(out vehicle))
            {
                vehicle.Internal.askDamage(vehicle.Internal.health, false);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully destroyed a vehicle!");
                }
                return;
            }
            queue.HandleError(entry, "That entity can't be damaged!");
        }
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1));
         if (num.Internal < 0)
         {
             queue.HandleError(entry, "Must provide a non-negative number!");
             return;
         }
         EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));
         if (entity == null)
         {
             queue.HandleError(entry, "Invalid entity!");
             return;
         }
         EPlayerKill kill; // for use with "out EPlayerKill" parameters
         PlayerTag   player;
         if (entity.TryGetPlayer(out player))
         {
             PlayerLife          life             = player.Internal.player.life;
             UFMHealthController healthController = player.Internal.player.GetComponent <UFMHealthController>();
             uint health = healthController != null ? healthController.health : life.health;
             if (num.Internal >= health)
             {
                 uint amount = (uint)num.Internal;
                 if (healthController != null)
                 {
                     healthController.health = 0;
                 }
                 if (amount >= byte.MaxValue) // TODO: better handling
                 {
                     life._health = 0;
                     amount       = 1;
                 }
                 life.askDamage((byte)amount, Vector3.zero, EDeathCause.KILL, ELimb.SPINE, CSteamID.Nil, out kill, null);
             }
             else
             {
                 uint amount = (uint)num.Internal;
                 if (healthController != null)
                 {
                     healthController.Damage((uint)num.Internal);
                 }
                 life._health = healthController.Translate();
                 life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                 {
                     life.health
                 });
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a player by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         ZombieTag zombie;
         if (entity.TryGetZombie(out zombie))
         {
             uint xp;
             zombie.Internal.askDamage((byte)num.Internal, Vector3.zero, out kill, out xp);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a zombie by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         AnimalTag animal;
         if (entity.TryGetAnimal(out animal))
         {
             uint xp;
             animal.Internal.askDamage((byte)num.Internal, Vector3.zero, out kill, out xp);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged an animal by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         BarricadeTag barricade;
         if (entity.TryGetBarricade(out barricade))
         {
             // TODO: Use BarricadeManager?
             barricade.InternalData.barricade.askDamage((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a barricade by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         ResourceTag resource;
         if (entity.TryGetResource(out resource))
         {
             // TODO: Use ResourceManager?
             resource.Internal.askDamage((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a resource by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         StructureTag structure;
         if (entity.TryGetStructure(out structure))
         {
             // TODO: Use StructureManager?
             structure.InternalData.structure.askDamage((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a structure by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         VehicleTag vehicle;
         if (entity.TryGetVehicle(out vehicle))
         {
             vehicle.Internal.askDamage((ushort)num.Internal, false);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a vehicle by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         queue.HandleError(entry, "That entity can't be damaged!");
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, "Failed to damage entity: " + ex.ToString());
     }
 }
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));

            if (entity == null)
            {
                queue.HandleError(entry, "Invalid entity!");
                return;
            }
            PlayerTag player;

            if (entity.TryGetPlayer(out player)) // TODO: Kick?
            {
                Provider.kick(player.Internal.playerID.steamID, "Removed forcibly.");
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully removed a player!");
                }
                return;
            }
            ZombieTag zombie;

            if (entity.TryGetZombie(out zombie)) // TODO: Remove!
            {
                zombie.Internal.health = 0;
                ZombieManager.sendZombieDead(zombie.Internal, new Vector3(9999, 9999, -9999));
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully removed a zombie!");
                }
                return;
            }
            AnimalTag animal;

            if (entity.TryGetAnimal(out animal))
            {
                animal.Internal.health = 0;
                AnimalManager.sendAnimalDead(animal.Internal, new Vector3(9999, 9999, -9999));
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully removed an animal!");
                }
                return;
            }
            BarricadeTag barricade;

            if (entity.TryGetBarricade(out barricade))
            {
                // TODO: Use BarricadeManager magic to remove properly?
                barricade.InternalData.barricade.askDamage(barricade.InternalData.barricade.health);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully destroyed a barricade!");
                }
                return;
            }
            ResourceTag resource;

            if (entity.TryGetResource(out resource)) // TODO: Remove!
            {
                // TODO: Use ResourceManager magic to remove properly?
                resource.Internal.askDamage(resource.Internal.health);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully destroyed a resource!");
                }
                return;
            }
            StructureTag structure;

            if (entity.TryGetStructure(out structure)) // TODO: Remove!
            {
                // TODO: Use StructureManager magic to remove properly?
                structure.InternalData.structure.askDamage(structure.InternalData.structure.health);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully destroyed a structure!");
                }
                return;
            }
            VehicleTag vehicle;

            if (entity.TryGetVehicle(out vehicle)) // TODO: Remove!
            {
                vehicle.Internal.health = 0;
                VehicleManager.sendVehicleExploded(vehicle.Internal);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully removed a vehicle!");
                }
                return;
            }
            queue.HandleError(entry, "That entity can't be damaged!");
        }