Пример #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);
                }
            }
        }
    }
Пример #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));
                }
            }
        }
Пример #3
0
        public static void PlacePatrol(Players.Player player, PlayerClickedData playerClickData)
        {
            if (playerClickData.IsConsumed || player.ActiveColony == null || playerClickData.HitType != PlayerClickedData.EHitType.Block)
            {
                return;
            }

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

            if (click.TypeSelected == Item.ItemIndex)
            {
                if (rayCastHit.TypeHit != PatrolFlag.ItemIndex)
                {
                    var flagPoint = rayCastHit.BlockHit.Add(0, 1, 0);

                    if (click.ClickType == PlayerClickedData.EClickType.Left)
                    {
                        var hasFlags = player.TakeItemFromInventory(PatrolFlag.ItemIndex);

                        if (!hasFlags)
                        {
                            if (player.ActiveColony.Stockpile.Contains(PatrolFlag.ItemIndex))
                            {
                                hasFlags = true;
                                player.ActiveColony.Stockpile.TryRemove(PatrolFlag.ItemIndex);
                            }
                        }

                        if (!hasFlags)
                        {
                            PandaChat.Send(player, _localizationHelper, "NoFlags", ChatColor.orange);
                        }
                        else
                        {
                            state.FlagsPlaced.Add(flagPoint);
                            ServerManager.TryChangeBlock(flagPoint, PatrolFlag.ItemIndex);
                            PandaChat.Send(player, _localizationHelper, "CreateJob", ChatColor.orange, state.FlagsPlaced.Count.ToString());
                        }
                    }
                }
                else
                {
                    foreach (var knight in Knight.Knights[player.ActiveColony])
                    {
                        if (knight.PatrolPoints.Contains(rayCastHit.BlockHit))
                        {
                            var patrol = string.Empty;

                            if (knight.PatrolType == PatrolType.RoundRobin)
                            {
                                patrol            = "RoundRobinDescription";
                                knight.PatrolType = PatrolType.WaitRoundRobin;
                            }
                            if (knight.PatrolType == PatrolType.WaitRoundRobin)
                            {
                                patrol            = "ZipperDescription";
                                knight.PatrolType = PatrolType.Zipper;
                            }
                            if (knight.PatrolType == PatrolType.Zipper)
                            {
                                patrol            = "WaitRoundRobinDescription";
                                knight.PatrolType = PatrolType.WaitZipper;
                            }
                            else
                            {
                                patrol            = "WaitZipperDescription";
                                knight.PatrolType = PatrolType.RoundRobin;
                            }

                            PandaChat.Send(player, _localizationHelper, "PatrolTypeSet", ChatColor.orange, knight.PatrolType.ToString());
                            PandaChat.Send(player, _localizationHelper, patrol, ChatColor.orange);
                            break;
                        }
                    }
                }
            }

            if (click.TypeSelected == Item.ItemIndex && click.ClickType == PlayerClickedData.EClickType.Right)
            {
                if (state.FlagsPlaced.Count == 0)
                {
                    PandaChat.Send(player, _localizationHelper, "MustPlaceFlag", ChatColor.orange);
                }
                else
                {
                    var knight = new Knight(new List <Vector3Int>(state.FlagsPlaced), player.ActiveColony);
                    state.FlagsPlaced.Clear();
                    player.ActiveColony.JobFinder.RegisterJobAdded(knight);

                    PandaChat.Send(player, _localizationHelper, "Active", ChatColor.orange);

                    player.ActiveColony.JobFinder.Update();
                    player.ActiveColony.SendCommonData();
                }
            }
        }
Пример #4
0
        public static void PlacePatrol(Players.Player player, Pipliz.Box <Shared.PlayerClickedData> boxedData)
        {
            if (boxedData.item1.IsConsumed)
            {
                return;
            }

            var click = boxedData.item1;

            Shared.VoxelRayCastHit rayCastHit = click.rayCastHit;
            var state = PlayerState.GetPlayerState(player);

            if (rayCastHit.rayHitType == Shared.RayHitType.Block &&
                click.typeSelected == Item.ItemIndex)
            {
                var stockpile = Stockpile.GetStockPile(player);

                if (click.typeHit != PatrolFlag.ItemIndex)
                {
                    var flagPoint = rayCastHit.voxelHit.Add(0, 1, 0);

                    if (click.clickType == Shared.PlayerClickedData.ClickType.Left)
                    {
                        bool hasFlags = player.TakeItemFromInventory(PatrolFlag.ItemIndex);

                        if (!hasFlags)
                        {
                            var playerStock = Stockpile.GetStockPile(player);

                            if (playerStock.Contains(PatrolFlag.ItemIndex))
                            {
                                hasFlags = true;
                                playerStock.TryRemove(PatrolFlag.ItemIndex);
                            }
                        }

                        if (!hasFlags)
                        {
                            PandaChat.Send(player, "You have no patrol flags in your stockpile or inventory.", ChatColor.orange);
                        }
                        else
                        {
                            state.FlagsPlaced.Add(flagPoint);
                            ServerManager.TryChangeBlock(flagPoint, PatrolFlag.ItemIndex);
                            PandaChat.Send(player, $"Patrol Point number {state.FlagsPlaced.Count} Registered! Right click to create Job.", ChatColor.orange);
                        }
                    }
                }
                else
                {
                    foreach (var knight in Knight.Knights[player])
                    {
                        if (knight.PatrolPoints.Contains(rayCastHit.voxelHit))
                        {
                            string patrol = string.Empty;

                            if (knight.PatrolType == PatrolType.RoundRobin)
                            {
                                patrol            = "The knight will patrol from the first to last point, then, work its way backwords to the first. Good for patrolling a secion of a wall";
                                knight.PatrolType = PatrolType.Zipper;
                            }
                            else
                            {
                                patrol            = "The knight will patrol from the first to last point, start over at the first point. Good for circles";
                                knight.PatrolType = PatrolType.RoundRobin;
                            }

                            PandaChat.Send(player, $"Patrol type set to {knight.PatrolType}!", ChatColor.orange);
                            PandaChat.Send(player, patrol, ChatColor.orange);
                            break;
                        }
                    }
                }
            }

            if (click.typeSelected == Item.ItemIndex && click.clickType == Shared.PlayerClickedData.ClickType.Right)
            {
                if (state.FlagsPlaced.Count == 0)
                {
                    PandaChat.Send(player, "You must place patrol flags using left click before setting the patrol.", ChatColor.orange);
                }
                else
                {
                    var knight = new Knight(new List <Pipliz.Vector3Int>(state.FlagsPlaced), player);
                    state.FlagsPlaced.Clear();
                    JobTracker.Add(knight);
                    PandaChat.Send(player, "Patrol Active! To stop the patrol pick up any of the patrol flags in the patrol.", ChatColor.orange);
                    JobTracker.Update();
                }
            }
        }