コード例 #1
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1));

            if (num.Internal <= 0)
            {
                queue.HandleError(entry, "Must provide a number that is greater than 0!");
                return;
            }
            EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));

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

            if (entity.TryGetZombie(out zombie))
            {
                Zombie inZomb = zombie.Internal;
                inZomb.maxHealth = (ushort)num.Internal;
                if (inZomb.health > inZomb.maxHealth)
                {
                    inZomb.health = inZomb.maxHealth;
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully set health of a zombie to " + inZomb.maxHealth + "!");
                }
                return;
            }
            PlayerTag player;

            if (entity.TryGetPlayer(out player))
            {
                GameObject          playerObj  = player.Internal.player.gameObject;
                UFMHealthController controller = playerObj.GetComponent <UFMHealthController>();
                if (controller == null)
                {
                    controller = playerObj.AddComponent <UFMHealthController>();
                }
                controller.maxHealth = (uint)num.Internal;
                PlayerLife life = player.Internal.player.life;
                byte       curr = life.health;
                controller.health = curr >= controller.maxHealth ? controller.maxHealth : curr;
                life._health      = controller.Translate();
                life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                {
                    life.health
                });
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully set max health of a player to " + controller.maxHealth + "!");
                }
                return;
            }
            queue.HandleError(entry, "That entity can't be healed!");
        }
コード例 #2
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()));
     }
 }
コード例 #3
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;
         }
         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());
     }
 }