public ActionResult RefreshAllSessionXP() { foreach (Session s in db.Sessions) { XPTransaction oldTrans = s.XPTransaction; XPTransaction trans = new XPTransaction(); trans.Description = s.XPTransaction.Description; trans.Id = Guid.NewGuid(); trans.Timestamp = s.XPTransaction.Timestamp; foreach (Session newS in s.XPTransaction.Sessions) { trans.Sessions.Add(newS); } s.XPTransaction = trans; List <XPChange> RemoveChanges = new List <XPChange>(oldTrans.Changes); foreach (XPChange chng in RemoveChanges) { db.XPChanges.Remove(chng); } db.XPTransactions.Remove(oldTrans); //trans.Changes.Clear(); foreach (Character c in s.Characters) { XPAsset XPPool = null; foreach (XPAsset curXPAsset in c.XPAssets) { if (curXPAsset.Name.Equals("XP Pool")) { XPPool = curXPAsset; } } if (XPPool != null) { XPChange xpChange = new XPChange(); xpChange.Amount = int.Parse(s.BaseXP); xpChange.Transaction = trans; xpChange.XPTransactionId = trans.Id; xpChange.XPAsset = XPPool; xpChange.XPAssetId = XPPool.Id; xpChange.Id = Guid.NewGuid(); trans.Changes.Add(xpChange); } else { //trans.Id = Guid.NewGuid(); } } } db.SaveChanges(); XPAsset.RefreshAllXPAssets(); return(Redirect("~/Sessions/Index")); }
public ActionResult UpgradeXPAsset(Guid idCharacter, Guid idSkill) { Character c = db.Characters.Find(idCharacter); XPAsset asset = db.XPAssets.Find(idSkill); if (c != null && asset != null) { XPAsset XPPool = c.XPAssets.Where(x => x.Name == "XP Pool").First(); int iPoints = XPPool.AllocatedXP.Value; if (asset.XPToUpgrade <= iPoints) { XPTransaction newTransaction = new XPTransaction(); newTransaction.Id = Guid.NewGuid(); newTransaction.Description = "XP Spend"; newTransaction.Timestamp = DateTime.Now; XPChange chgAddToAsset = new XPChange(); chgAddToAsset.Id = Guid.NewGuid(); chgAddToAsset.Transaction = newTransaction; chgAddToAsset.XPAsset = asset; chgAddToAsset.Amount = asset.XPToUpgrade; XPChange chgDeductFromPool = new XPChange(); chgDeductFromPool.Id = Guid.NewGuid(); chgDeductFromPool.Transaction = newTransaction; chgDeductFromPool.XPAsset = XPPool; chgDeductFromPool.Amount = -asset.XPToUpgrade; newTransaction.Changes.Add(chgAddToAsset); newTransaction.Changes.Add(chgDeductFromPool); db.XPTransactions.Add(newTransaction); db.XPChanges.Add(chgAddToAsset); db.XPChanges.Add(chgDeductFromPool); db.SaveChanges(); XPAsset.RefreshAllXPAssets(); } } if (Request != null) { return(new RedirectResult(Request.UrlReferrer.AbsoluteUri)); } else { return(RedirectToAction("Details", idCharacter)); } }
public ActionResult SpendEdgePoint(Guid id) { Character c = db.Characters.Find(id); if (c != null) { //TODO: Ensure user is allowed to make this change EdgePoints ep = c.XPAssets.Where(x => x.Name == "Edge Points").First() as EdgePoints; if (ep != null) { if (ep.AllocatedXP.Value >= 20) { XPTransaction newTransaction = new XPTransaction(); newTransaction.Id = Guid.NewGuid(); newTransaction.Description = "Edge Point Spent"; newTransaction.Timestamp = DateTime.Now; XPChange chgDeductFromPool = new XPChange(); chgDeductFromPool.Id = Guid.NewGuid(); chgDeductFromPool.Transaction = newTransaction; chgDeductFromPool.XPAsset = ep; chgDeductFromPool.Amount = -20; newTransaction.Changes.Add(chgDeductFromPool); db.XPTransactions.Add(newTransaction); db.XPChanges.Add(chgDeductFromPool); db.SaveChanges(); XPAsset.RefreshAllXPAssets(); } } } if (Request != null) { return(new RedirectResult(Request.UrlReferrer.AbsoluteUri)); } else { return(RedirectToAction("Details", id)); } }