// GET: Action
        public IActionResult Index(ActionModel actionModel)
        {
            var model = ActionModel.NewActionModel(db, User.Identity.Name);

            var data = new DataCache(db, model.User, model.Corporation);
            data.RefreshCache();
            model.DataCache = data;

            if (model.Corporation.TurnCount > 1)
            {
                model.Messages = LogService.GetLogsByTurn(db, model.Corporation, model.Corporation.TurnCount - 1);
            }

            data.RefreshCache();
            model.BuildViewItems(db);

            return View(model);
        }
        public IActionResult EndTurn(ClientActionModel clientModel)
        {
            var newModel = ActionModel.NewActionModel(db, User.Identity.Name);
            var data = new DataCache(db, newModel.User, newModel.Corporation);
            newModel.DataCache = data;

            ActionService.PerformActions(db, clientModel, data);
            ActionService.ResolveState(db, clientModel, data);

            data.RefreshCache();

            newModel.BuildViewItems(db);

            return Json(newModel);
        }
Beispiel #3
0
        public static void ResolveState(ApplicationDbContext db, ClientActionModel model, DataCache data)
        {
            data.RefreshCache();
            //Advance research node states
            var nodes = data.ActiveResearchNodes.Where(n => n.Corporation.Id == data.Corporation.Id).ToList();
            nodes.ForEach(n =>
            {
                n.RDInvested += data.Corporation.RD;
                if (n.RDInvested >= n.ResearchNode.RDCost)
                {
                    db.LearnedResearchNodes.Add(new LearnedResearchNode()
                    {
                        Corporation = data.Corporation,
                        ResearchNode = n.ResearchNode,
                    });
                    db.ActiveResearchNodes.Remove(n);
                    LogService.Log(db, data.Corporation, "Learned research node " + n.ResearchNode.Name);
                }
            });

            //Take out salaries
            var hired = CorporationPerson.GetPeopleByHiredStatus(true, data.CorporationPersons);
            foreach (var p in hired)
            {
                data.Corporation.Cash -= p.Person.TurnSalary;
                if (data.Corporation.Cash < 0) LogService.Log(db, data.Corporation, "You are unabel to pay your employees! When they don't get paid, their happiness drops, and they might quit.");
            }

            //Resolve Contracts
            ContractService.MoveContractsToActive(db, data);

            data.Corporation.TurnCount++;
            db.SaveChanges();
        }