예제 #1
0
        public static void OnTryChangeBlock(ModLoader.OnTryChangeBlockData userData)
        {
            Players.Player causedBy = null;
            if (userData.RequestOrigin.Type == BlockChangeRequestOrigin.EType.Player)
            {
                causedBy = userData.RequestOrigin.AsPlayer;
            }
            if (causedBy == null || AngryGuards.ModeSetting != GuardMode.Passive || PermissionsManager.HasPermission(causedBy, AngryGuards.PERMISSION_PREFIX + ".peacekeeper"))
            {
                return;
            }

            // check if the block change is within range of a banner(colony)
            foreach (Colony checkColony in ServerManager.ColonyTracker.ColoniesByID.Values)
            {
                if (IsOwnerOrFriendly(checkColony, causedBy))
                {
                    continue;
                }
                foreach (BannerTracker.Banner checkBanner in checkColony.Banners)
                {
                    int distanceX = (int)System.Math.Abs(causedBy.Position.x - checkBanner.Position.x);
                    int distanceZ = (int)System.Math.Abs(causedBy.Position.z - checkBanner.Position.z);
                    if (distanceX < PassiveProtectionRange && distanceZ < PassiveProtectionRange)
                    {
                        PlayerTracker.AddEnemy(checkColony, causedBy);
                        return;
                    }
                }
            }
            return;
        }
예제 #2
0
 public static bool IsOwnerOrFriendly(Colony colony, Players.Player candidate)
 {
     if (colony.Owners.ContainsByReference(candidate))
     {
         return(true);
     }
     foreach (Players.Player owner in colony.Owners)
     {
         if (PlayerTracker.IsFriendly(owner, candidate))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #3
0
        public static void OnNPCHit(NPC.NPCBase npc, ModLoader.OnHitData data)
        {
            if (!(data.HitSourceObject is Players.Player))
            {
                return;
            }
            Players.Player killer = (Players.Player)data.HitSourceObject;
            foreach (Players.Player owner in npc.Colony.Owners)
            {
                if (owner == killer || PlayerTracker.IsFriendly(owner, killer))
                {
                    return;
                }
            }

            PlayerTracker.AddEnemy(npc.Colony, killer);
        }
예제 #4
0
        // perform guard duty
        public void OnNPCAtJob(BlockJobInstance blockInstance, ref NPCBase.NPCState state)
        {
            AngryGuardJobInstance instance = (AngryGuardJobInstance)blockInstance;

            instance.target = PlayerTracker.FindTarget(instance.Owner, instance.eyePosition, this.Range);

            if (instance.target != null)
            {
                Vector3 positionToAimFor = instance.target.Position;
                positionToAimFor[1] += 1;
                instance.NPC.LookAt(positionToAimFor);
                this.ShootAtTarget(instance, ref state);
            }
            else
            {
                state.SetCooldown((double)this.CooldownSearchingTarget);
                Vector3 val = instance.Position.Vector;
                int     num;
                if (this.BlockTypes.ContainsByReference <ItemTypes.ItemType>(instance.BlockType, out num))
                {
                    switch (num)
                    {
                    case 1:
                        val += Vector3.right;
                        break;

                    case 2:
                        val += Vector3.left;
                        break;

                    case 3:
                        val += Vector3.forward;
                        break;

                    case 4:
                        val += Vector3.back;
                        break;
                    }
                    instance.NPC.LookAt(val);
                }
            }
            return;
        }
예제 #5
0
        public bool TryDoCommand(Players.Player causedBy, string chattext, List <string> splits)
        {
            if (!splits[0].Equals("/friendly"))
            {
                return(false);
            }

            var m = Regex.Match(chattext, @"/friendly (?<action>[^ ]+) ?(?<player>['].+[']|[^ ]+)?$");

            if (!m.Success)
            {
                return(SyntaxError(causedBy));
            }
            string action = m.Groups["action"].Value;

            if (!(action.Equals("add") || action.Equals("list") || action.Equals("remove")))
            {
                return(SyntaxError(causedBy));
            }

            // list does not require a target player
            if (action.Equals("list"))
            {
                string playerNames;
                if (PlayerTracker.GetFriendlyList(causedBy, out playerNames))
                {
                    Chat.Send(causedBy, $"Friendly players: {playerNames}");
                }
                else
                {
                    Chat.Send(causedBy, "No friendly players defined. Guards shoot everyone.");
                }
                return(true);
            }

            string playerName = m.Groups["player"].Value;
            string error;

            Players.Player target;
            if (!PlayerHelper.TryGetPlayer(playerName, out target, out error, true))
            {
                Chat.Send(causedBy, $"Could not find player {playerName}: {error}");
                return(true);
            }

            if (action.Equals("add"))
            {
                if (!PlayerTracker.AddFriendly(causedBy, target))
                {
                    Chat.Send(causedBy, $"Player {target.Name} is already on the friendly list");
                    return(true);
                }
                else
                {
                    Chat.Send(causedBy, $"Added {target.Name} as friendly");
                }
            }
            else if (action.Equals("remove"))
            {
                if (!PlayerTracker.RemoveFriendly(causedBy, target))
                {
                    Chat.Send(causedBy, $"Player {target.Name} was not on the friendly list");
                }
                else
                {
                    Chat.Send(causedBy, $"Removed {target.Name} from friendly list");
                }
            }

            return(true);
        }
예제 #6
0
 public static void OnQuit()
 {
     PlayerTracker.Save();
 }
예제 #7
0
 public static void AfterWorldLoad()
 {
     PlayerTracker.Load();
 }