Beispiel #1
0
 public void changeStructure(shared.Vector2Int location, Structure.StructureType newType)
 {
     if (ownedOutposts.ContainsKey(location))
     {
         Structure str = NewStructure(location, newType);
         ownedOutposts[location] = str;
         GameServer.Instance.Structures.SetStructure(str);
     }
 }
Beispiel #2
0
 public void SendCommand(shared.Vector2Int location, string command, string args)
 {
     if (ownedOutposts.ContainsKey(location))
     {
         ownedOutposts[location].CallCommand(command, args);
     }
     else
     {
         Logger.LogError("No structure at " + location);
     }
 }
Beispiel #3
0
        public bool CanCreateStructure(shared.Vector2Int location, out shared.MessageTypes reason)
        {
            if (!GameServer.Instance.Structures.CanCreateStructure(location))
            {
                reason = shared.MessageTypes.Invalid_Structure_Location;
                return(false);
            }

            // has resources?
            reason = shared.MessageTypes.None;
            return(true);
        }
Beispiel #4
0
        public Structure[] GetOps(shared.Vector2Int topLeft, shared.Vector2Int bottomRight, Dictionary <shared.Vector2Int, Structure> dict)
        {
            List <Structure> result = new List <Structure>();

            foreach (shared.Vector2Int position in dict.Keys)
            {
                if (position.x >= topLeft.x && position.x <= bottomRight.x &&
                    position.y <= topLeft.y && position.y >= bottomRight.y)
                {
                    result.Add(dict[position]);
                }
            }
            return(result.ToArray());
        }
Beispiel #5
0
        public Structure CreateStructure(shared.Vector2Int location, Structure.StructureType type, bool updateImmediately)
        {
            Structure str = NewStructure(location, type);

            if (str != null)
            {
                if (!ownedOutposts.ContainsKey(str.Location))
                {
                    ownedOutposts.Add(str.Location, str);
                }
                GameServer.Instance.Structures.AddStructure(str, updateImmediately);
            }
            return(str);
        }
Beispiel #6
0
        public Structure[] GetOwnedOps(shared.Vector2Int topLeft, shared.Vector2Int bottomRight, bool onlyChanged)
        {
            Structure[]      owned        = GetOps(topLeft, bottomRight, ownedOutposts);
            List <Structure> ownedChanged = new List <Structure>();

            if (onlyChanged)
            {
                for (int i = 0; i < owned.Length; i++)
                {
                    if (GameServer.Instance.Structures.ChangedThisTick(owned[i].Location))
                    {
                        ownedChanged.Add(owned[i]);
                    }
                }
            }
            else
            {
                ownedChanged.AddRange(owned);
            }

            return(ownedChanged.ToArray());
        }
Beispiel #7
0
        public Structure[] GetVisibleOps(shared.Vector2Int topLeft, shared.Vector2Int bottomRight, bool onlychanged)
        {
            SetVisibleOps();
            Structure[]      visible        = GetOps(topLeft, bottomRight, visibleOutposts);
            List <Structure> visibleChanged = new List <Structure>();

            if (onlychanged)
            {
                for (int i = 0; i < visible.Length; i++)
                {
                    if (GameServer.Instance.Structures.ChangedLastTick(visible[i].Location))
                    {
                        visibleChanged.Add(visible[i]);
                    }
                }
            }
            else
            {
                visibleChanged.AddRange(visible);
            }
            return(visibleChanged.ToArray());
        }
Beispiel #8
0
        public Structure NewStructure(shared.Vector2Int location, Structure.StructureType type)
        {
            Structure str = null;

            switch (type)
            {
            case Structure.StructureType.None:
                str = new None(location, this);
                break;

            case Structure.StructureType.City:
                str = new City(location, this);
                break;

            case Structure.StructureType.Outpost:
                str = new Outpost(location, this);
                break;

            case Structure.StructureType.Radar:
                str = new Radar(location, this, AppSettings.BaseRadarRadius);
                break;
            }
            return(str);
        }
Beispiel #9
0
        public bool CanUpgradeStructure(shared.Vector2Int location, Structure.StructureType newType, out shared.MessageTypes reason)
        {
            if (!ownedOutposts.ContainsKey(location))
            {
                reason = shared.MessageTypes.No_OP;
                return(false);
            }
            Structure structure = ownedOutposts[location];

            if (structure.Type != Structure.StructureType.Outpost)
            {
                reason = shared.MessageTypes.Op_Not_Upgradable;
                return(false);
            }

            //check resources
            bool hasResources = true;

            if (!hasResources)
            {
                reason = shared.MessageTypes.Not_Enough_Resources;
                return(false);
            }

            //check age
            bool validAge = true;

            if (!validAge)
            {
                reason = shared.MessageTypes.Invalid_Op_Age;
                return(false);
            }

            reason = shared.MessageTypes.Success;
            return(true);
        }