Ejemplo n.º 1
0
 new public void InitializeJob(Players.Player owner, Vector3Int position, int desiredNPCID)
 {
     this.position = position;
     this.owner    = owner;
     if (desiredNPCID != 0 && NPCTracker.TryGetNPC(desiredNPCID, out usedNPC))
     {
         usedNPC.TakeJob(this);
     }
     else
     {
         desiredNPCID = 0;
     }
 }
Ejemplo n.º 2
0
        public DefaultFarmerAreaJob(Players.Player owner, Vector3Int min, Vector3Int max, int npcID = 0)
        {
            positionMin = min;
            positionMax = max;
            this.owner  = owner;

            NPCBase foundNPC = null;

            if (npcID != 0)
            {
                NPCTracker.TryGetNPC(npcID, out foundNPC);
            }
            NPC = foundNPC;
        }
Ejemplo n.º 3
0
        public virtual void InitializeJob(Players.Player owner, Vector3Int position, int desiredNPCID)
        {
            this.position = position;
            this.owner    = owner;

            NPCBase foundNPC = null;

            if (desiredNPCID != 0)
            {
                if (!NPCTracker.TryGetNPC(desiredNPCID, out foundNPC))
                {
                    Log.WriteWarning("Failed to find npc ID {0}", desiredNPCID);
                }
            }
            NPC = foundNPC;
        }
Ejemplo n.º 4
0
        public static void Click(Players.Player player, Box <PlayerClickedData> boxedData)
        {
            var healed = false;

            if (!_coolDown.ContainsKey(player))
            {
                _coolDown.Add(player, 0);
            }

            if (boxedData.item1.clickType == PlayerClickedData.ClickType.Right &&
                boxedData.item1.typeSelected == Item.ItemIndex)
            {
                if (Time.MillisecondsSinceStart > _coolDown[player])
                {
                    var healing = new HealingOverTimePC(player, INITIALHEAL, TOTALHOT, 5);
                    healed = true;
                }
            }
            else if (boxedData.item1.clickType == PlayerClickedData.ClickType.Left &&
                     boxedData.item1.typeSelected == Item.ItemIndex &&
                     boxedData.item1.rayCastHit.rayHitType == RayHitType.NPC)
            {
                if (NPCTracker.TryGetNPC(boxedData.item1.rayCastHit.hitNPCID, out var npc))
                {
                    if (Time.MillisecondsSinceStart > _coolDown[player])
                    {
                        var heal = new HealingOverTimeNPC(npc, INITIALHEAL, TOTALHOT, 5, Item.ItemIndex);
                        healed = true;
                    }
                }
            }

            if (healed)
            {
                _coolDown[player]            = Time.MillisecondsSinceStart + COOLDOWN;
                boxedData.item1.consumedType = PlayerClickedData.ConsumedType.UsedByMod;
                ServerManager.SendAudio(player.Position, GameLoader.NAMESPACE + ".Bandage");

                if (Inventory.TryGetInventory(player, out var inv))
                {
                    inv.TryRemove(Item.ItemIndex);
                }
            }
        }
Ejemplo n.º 5
0
        public DefaultFarmerAreaJob(Players.Player owner, Vector3Int min, Vector3Int max, int npcID = 0)
        {
            positionMin = min;
            positionMax = max;
            this.owner  = owner;

            if (npcID != 0 && NPCTracker.TryGetNPC(npcID, out usedNPC))
            {
                usedNPC.TakeJob(this);
            }
            else
            {
                npcID = 0;
            }
            if (usedNPC == null)
            {
                JobTracker.Add(this);
            }
        }
Ejemplo n.º 6
0
        public virtual void InitializeJob(Players.Player owner, Vector3Int position, int desiredNPCID)
        {
            this.position = position;
            this.owner    = owner;

            if (desiredNPCID != 0)
            {
                if (NPCTracker.TryGetNPC(desiredNPCID, out usedNPC))
                {
                    usedNPC.TakeJob(this);
                }
                else
                {
                    Log.WriteWarning("Failed to find npc ID {0}", desiredNPCID);
                }
            }
            if (usedNPC == null)
            {
                JobTracker.Add(this);
            }
        }
Ejemplo n.º 7
0
        public static void Click(Players.Player player, PlayerClickedData playerClickData)
        {
            var healed = false;

            if (!_coolDown.ContainsKey(player))
            {
                _coolDown.Add(player, 0);
            }

            if (playerClickData.ClickType == PlayerClickedData.EClickType.Right &&
                playerClickData.TypeSelected == Item.ItemIndex)
            {
                if (Time.MillisecondsSinceStart > _coolDown[player])
                {
                    var healing = new HealingOverTimePC(player, INITIALHEAL, TOTALHOT, 5);
                    healed = true;
                }
            }
            else if (playerClickData.ClickType == PlayerClickedData.EClickType.Left &&
                     playerClickData.TypeSelected == Item.ItemIndex &&
                     playerClickData.HitType == PlayerClickedData.EHitType.NPC)
            {
                if (NPCTracker.TryGetNPC(playerClickData.GetNPCHit().NPCID, out var npc))
                {
                    if (Time.MillisecondsSinceStart > _coolDown[player])
                    {
                        var heal = new HealingOverTimeNPC(npc, INITIALHEAL, TOTALHOT, 5, Item.ItemIndex);
                        healed = true;
                    }
                }
            }

            if (healed)
            {
                _coolDown[player]            = Time.MillisecondsSinceStart + COOLDOWN;
                playerClickData.ConsumedType = PlayerClickedData.EConsumedType.UsedByMod;
                AudioManager.SendAudio(player.Position, GameLoader.NAMESPACE + ".Bandage");
                player.Inventory.TryRemove(Item.ItemIndex);
            }
        }
Ejemplo n.º 8
0
        public static void WeaponAttack(Players.Player player, Box <PlayerClickedData> boxedData)
        {
            if (boxedData.item1.IsConsumed)
            {
                return;
            }

            var click      = boxedData.item1;
            var rayCastHit = click.rayCastHit;
            var state      = PlayerState.GetPlayerState(player);

            if (WeaponLookup.ContainsKey(click.typeSelected) &&
                click.rayCastHit.rayHitType == RayHitType.NPC &&
                click.clickType == PlayerClickedData.ClickType.Left)
            {
                var millisecondsSinceStart = Time.MillisecondsSinceStart;

                if (state.Weapon.IsEmpty() || state.Weapon.Id != click.typeSelected)
                {
                    state.Weapon = new SettlerInventory.ArmorState
                    {
                        Id         = click.typeSelected,
                        Durability = WeaponLookup[click.typeSelected].Durability
                    }
                }
                ;

                if (Players.LastPunches.TryGetValue(player, out var num) &&
                    millisecondsSinceStart - num < Players.PlayerPunchCooldownMS)
                {
                    return;
                }

                Players.LastPunches[player]  = millisecondsSinceStart;
                boxedData.item1.consumedType = PlayerClickedData.ConsumedType.UsedByMod;

                if (ZombieID.IsZombieID(rayCastHit.hitNPCID))
                {
                    if (MonsterTracker.TryGetMonsterByID(rayCastHit.hitNPCID, out var monster))
                    {
                        monster.OnHit(WeaponLookup[click.typeSelected].Damage);
                        state.Weapon.Durability--;
                        ServerManager.SendAudio(monster.PositionToAimFor, "punch");
                    }
                }
                else if (NPCTracker.TryGetNPC(rayCastHit.hitNPCID, out var nPCBase))
                {
                    nPCBase.OnHit(WeaponLookup[click.typeSelected].Damage);
                    state.Weapon.Durability--;
                    ServerManager.SendAudio(nPCBase.Position.Vector, "punch");
                }

                if (state.Weapon.Durability <= 0)
                {
                    state.Weapon = new SettlerInventory.ArmorState();
                    player.TakeItemFromInventory(click.typeSelected);

                    PandaChat.Send(player,
                                   $"Your {WeaponLookup[click.typeSelected].Metal} {WeaponLookup[click.typeSelected].WeaponType} has broke!",
                                   ChatColor.orange);
                }
            }
        }
    }
Ejemplo n.º 9
0
        public static void WeaponAttack(Players.Player player, PlayerClickedData playerClickData)
        {
            if (playerClickData.IsConsumed)
            {
                return;
            }

            var click = playerClickData;
            var state = PlayerState.GetPlayerState(player);

            if (WeaponLookup.ContainsKey(click.TypeSelected) &&
                click.HitType == PlayerClickedData.EHitType.NPC &&
                click.ClickType == PlayerClickedData.EClickType.Left)
            {
                var millisecondsSinceStart = Time.MillisecondsSinceStart;

                if (state.Weapon.IsEmpty() || state.Weapon.Id != click.TypeSelected)
                {
                    state.Weapon = new ItemState
                    {
                        Id         = click.TypeSelected,
                        Durability = WeaponLookup[click.TypeSelected].WepDurability
                    }
                }
                ;

                if (Players.LastPunches.TryGetValue(player, out var num) &&
                    num.TimeSinceThis < Players.PlayerPunchCooldownMS)
                {
                    return;
                }

                Players.LastPunches[player]  = ServerTimeStamp.Now;
                playerClickData.ConsumedType = PlayerClickedData.EConsumedType.UsedByMod;
                var rayCastHit = click.GetNPCHit();

                if (ZombieID.IsZombieID(rayCastHit.NPCID))
                {
                    if (MonsterTracker.TryGetMonsterByID(rayCastHit.NPCID, out var monster))
                    {
                        var dmg = WeaponLookup[click.TypeSelected].Damage.TotalDamage();
                        state.IncrimentStat("Damage Delt", dmg);
                        monster.OnHit(dmg);
                        state.Weapon.Durability--;
                        AudioManager.SendAudio(monster.PositionToAimFor, "punch");
                    }
                }
                else if (NPCTracker.TryGetNPC(rayCastHit.NPCID, out var nPCBase))
                {
                    var dmg = WeaponLookup[click.TypeSelected].Damage.TotalDamage();
                    state.IncrimentStat("Damage Delt", dmg);
                    nPCBase.OnHit(dmg, player, ModLoader.OnHitData.EHitSourceType.PlayerClick);
                    state.Weapon.Durability--;
                    AudioManager.SendAudio(nPCBase.Position.Vector, "punch");
                }

                if (state.Weapon.Durability <= 0)
                {
                    state.Weapon = new ItemState();
                    player.TakeItemFromInventory(click.TypeSelected);

                    PandaChat.Send(player,
                                   _localizationHelper,
                                   "Broke",
                                   ChatColor.orange,
                                   ItemId.GetItemId(click.TypeSelected).LocalizedName(player));
                }
            }
        }