Exemplo n.º 1
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);
                }
            }
        }
    }
Exemplo n.º 2
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));
                }
            }
        }