Esempio n. 1
0
        private bool checkTechnology(ShipTemplate template, int userId, bool fastBuild, ref ShipBuildErrorCode errorCode, ref int errorValue)
        {
            User user = Core.Instance.users[userId];

            if (!user.hasGameObjectEnabled(5, template.hullid))
            {
                return(false);
            }

            if (fastBuild)
            {
                foreach (var module in template.shipModules)
                {
                    if (!user.hasModuleResearch(Core.Instance.Modules[module.moduleId]))
                    {
                        errorCode  = ShipBuildErrorCode.Technology;
                        errorValue = module.moduleId;
                        return(false);
                    }
                    //foreach(Core.Instance.ResearchQuestPrerequisites
                }
            }
            return(true);
        }
Esempio n. 2
0
        public static bool BuildModules(int userId, SpacegameServer.Core.Transfer transfer, ref string xml)
        {
            SpacegameServer.Core.Core core = SpacegameServer.Core.Core.Instance;

            if (!core.colonies.ContainsKey(transfer.Sender))
            {
                return(false);
            }

            Colony colony = core.colonies[transfer.Sender];

            if (colony.userId != userId)
            {
                return(false);
            }

            User user = Core.Instance.users[userId];

            //check if modules are researched:
            foreach (var moduleLine in transfer.Goods)
            {
                if (moduleLine.Qty < 0)
                {
                    return(false);
                }

                //check that the Module exists
                if (!Core.Instance.Modules.Any(e => e != null && e.goodsId == moduleLine.Id))
                {
                    return(false);
                }

                Module toBuild = Core.Instance.Modules.First(e => e != null && e.goodsId == moduleLine.Id);

                if (!user.hasModuleResearch(toBuild))
                {
                    return(false);
                }
            }

            if (!Modules.checkGoodsAvailability(colony, transfer))
            {
                return(false);
            }

            List <Lockable> elementsToLock = new List <Lockable>(3);

            elementsToLock.Add(colony);

            if (!LockingManager.lockAllOrSleep(elementsToLock))
            {
                return(false);
            }

            try
            {
                if (!Modules.checkGoodsAvailability(colony, transfer))
                {
                    return(false);
                }

                //remove TemplateModules
                foreach (var moduleLine in transfer.Goods)
                {
                    Module toBuild = core.Modules.First(e => e != null && e.goodsId == moduleLine.Id);

                    foreach (var costs in toBuild.ModulesCosts)
                    {
                        colony.addGood(costs.goodsId, -costs.amount * moduleLine.Qty, false);
                    }

                    colony.addGood(toBuild.goodsId, moduleLine.Qty, false);
                }

                Core.Instance.dataConnection.saveColonyGoods(colony);
            }
            catch (Exception ex)
            {
                SpacegameServer.Core.Core.Instance.writeExceptionToLog(ex);
            }
            finally
            {
                //release the ressources and return true
                LockingManager.unlockAll(elementsToLock);
            }

            return(true);
        }