Ejemplo n.º 1
0
        static public object Rit_MoonBridge(Thea2.Server.Group target, RitualsTask sourceTask)
        {
            if (target.settlement)
            {
                return(null);
            }

            List <Thea2.Server.Group> groups        = GameInstance.Get().GetValidPlayerGroups();
            List <Thea2.Server.Group> visibleGroups = new List <Thea2.Server.Group>(groups);

            //visibleGroups.AddRange(groups);
            visibleGroups.AddRange(GameInstance.Get().GetEnemyGroups());

            List <Vector3i> groupsPos = new List <Vector3i>();
            List <Vector3i> range     = new List <Vector3i>();

            foreach (var g in groups)
            {
                //check if testing group is different than target group and if group owner is equal to target owner
                if (g != target && g.ownerID == target.ownerID)
                {
                    groupsPos.Add(g.Position);
                }
            }

            //sort groups positions from nearest to farthest position
            groupsPos.Sort(delegate(Vector3i a, Vector3i b)
            {
                int distA = HexCoordinates.HexDistance(target.Position, a);
                int distB = HexCoordinates.HexDistance(target.Position, b);
                return(distA.CompareTo(distB));
            });

            //find proper group to teleport to
            foreach (Vector3i v in groupsPos)
            {
                //teleport is possible in range up to 5 hexes from available group, check from nearest to farthest hexes
                //find hexes in range
                //can't teleport on water
                //check if hex is occupied by enemy group, settlement or camping
                for (int i = 0; i <= 5; i++)
                {
                    range = HexNeighbors.GetRange(v, i);
                    foreach (var hex in range)
                    {
                        if (World.IsLand(hex) && !GameInstance.Get().GetGroupsToTeleport().ContainsValue(hex))
                        {
                            List <Thea2.Server.Group> obstacles = visibleGroups.FindAll(o => o.Position == hex && (o.ownerID < 0 || o.settlement || o.camping));
                            if (obstacles.Count > 0)
                            {
                                continue;
                            }
                            GameInstance.Get().AddToTeleport(target.ID, hex);
                            return(null);
                        }
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        static bool Prefix(Thea2.Server.Group __instance)
        {
            if (!__instance.settlement && !__instance.camping)
            {
                if (__instance.gatheringRangeArea != null)
                {
                    __instance.gatheringRangeArea.Clear();
                }
                else
                {
                    __instance.gatheringRangeArea = new List <Vector3i>();
                }
                return(false);
            }
            if (!__instance.settlement && (__instance.characters == null || __instance.characters.Count < 1))
            {
                if (__instance.gatheringRangeArea != null)
                {
                    __instance.gatheringRangeArea.Clear();
                }
                else
                {
                    __instance.gatheringRangeArea = new List <Vector3i>();
                }
                return(false);
            }
            SPlayer player = GameInstance.Get().GetPlayer(__instance.ownerID);

            if (__instance.camping && player != null && player.attributes.Contains(DBDef.TAG.CAMP_GATHERING_RANGE))
            {
                __instance.gatheringRange = (FInt)2;
            }
            __instance.gatheringRangeArea = HexNeighbors.GetRange(__instance.Position, __instance.gatheringRange.ToInt());
            List <Thea2.Server.Group> playerGroups = GameInstance.Get().GetPlayerGroups().FindAll((Group o) => o.ownerID == __instance.ownerID);

            if (playerGroups != null)
            {
                using (List <Group> .Enumerator enumerator = playerGroups.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Group v = enumerator.Current;
                        if (v != __instance)
                        {
                            if (v.settlement || v.camping)
                            {
                                if (v.settlement || (v.characters != null && v.characters.Count >= 1))
                                {
                                    if (v.gatheringRangeArea != null)
                                    {
                                        int b = HexCoordinates.HexDistance(v.Position, __instance.Position);
                                        if (!(v.gatheringRange + __instance.gatheringRange < b))
                                        {
                                            __instance.gatheringRangeArea = __instance.gatheringRangeArea.FindAll((Vector3i o) => !v.gatheringRangeArea.Contains(o));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }