/// <summary> /// Gets the slots available for the Owner. /// </summary> /// <returns></returns> private int GetSlotsAvailable() { int slots = 0; KinCityData.BeneficiaryData benData = GetBenData(); if (benData == null) { return(slots); } return(benData.UnassignedGuardSlots); }
/// <summary> /// Gets the benificary data of the Owner /// </summary> /// <returns></returns> private KinCityData.BeneficiaryData GetBenData() { KinCityData cityData = KinCityManager.GetCityData(GuardPost.City); if (cityData == null) { return(null); } KinCityData.BeneficiaryData benData = cityData.BeneficiaryDataList.Find(delegate(KinCityData.BeneficiaryData bd) { return(bd.Pm == GuardPost.Owner); }); return(benData); }
/// <summary> /// Commit any outstanding changes /// </summary> /// <param name="sender"></param> void ICommitGumpEntity.CommitChanges() { if (m_State.IsValueDirty <int>("VotedFor")) { string playerName = GetBeneficiaryNames()[m_State.GetValue <int>("VotedFor")]; KinCityData.BeneficiaryData bd = m_Gump.Data.GetBeneficiary(playerName); if (bd != null) { m_Gump.Data.CastVote(bd.Pm, m_Gump.From as PlayerMobile); } } }
/// <summary> /// Returns the total amount of assigned slots the benficary has /// </summary> /// <param name="data"></param> /// <returns></returns> public int CountAssignedSlots(KinCityData.BeneficiaryData data) { int slots = 0; //Add the present slot cost of each guard posts if (data.GuardPosts != null && data.GuardPosts.Count > 0) { foreach (KinGuardPost kgp in data.GuardPosts) { slots += (int)kgp.CostType; } } return(slots); }
/// <summary> /// Called when [delete]. /// </summary> public override void OnDelete() { //Give guard post slots back KinCityData data = KinCityManager.GetCityData(m_City); if (data == null) { base.OnDelete(); return; } KinCityData.BeneficiaryData bd = data.GetBeneficiary(m_Owner); if (bd == null) { base.OnDelete(); return; } bd.UnRegisterGuardPost(this); base.OnDelete(); }
/// <summary> /// Creation of the entity's graphics /// </summary> void ICommitGumpEntity.Create() { #region page 1 // Page 1 - overview ////////////////////////////////////////////////////////////////////// StringBuilder htmlSb = new StringBuilder("<basefont color=#FFCC00><center>Candidates for City Leadership</center></basefont>"); m_Gump.AddHtml(170, 40, 409, 19, htmlSb.ToString(), false, false); htmlSb = new StringBuilder("<basefont color=gray><center>Cast your vote by nominating a person below.</center></basefont>"); m_Gump.AddHtml(170, 80, 409, 19, htmlSb.ToString(), false, false); //left //If this is a gm+, show a button that allows the vote process to be stopped (for testing shit only) if (m_Gump.From.AccessLevel > AccessLevel.Counselor) { m_Gump.AddButton(47, 132, 5572, 5572, (int)Buttons.btnStopVoteStageEarly, GumpButtonType.Reply, 1); } CreateButtons(); KinCityData.BeneficiaryData bd = m_Gump.Data.GetBeneficiary(m_Gump.From as PlayerMobile); if (bd == null) { //This mobile is not a beneficiary of the city m_Gump.AddHtml(169, 425, 412, 136, "<basefont color=gray><center>You are not a beneficiary of this city and cannot vote</center></basefont>", false, false); m_CanVote = false; } else if (bd.HasVoted) { //This mobile has already voted.. m_Gump.AddHtml(169, 425, 412, 136, "<basefont color=gray><center>You have already voted for a leader and may not vote again</center></basefont>", false, false); m_CanVote = false; } else if (m_State.IsValueDirty <int>("VotedFor")) { m_Gump.AddHtml(169, 425, 412, 136, "<basefont color=gray><center>You must press OK before your vote is cast</center></basefont>", false, false); } ////////////////////////////////////////////////////////////////////////////////////////////// #endregion }
/// <summary> /// Restore data from the session /// </summary> void ICommitGumpEntity.LoadStateInfo() { m_State = (m_Gump.Session[((ICommitGumpEntity)this).ID] as DirtyState); if (m_State == null) { m_State = new DirtyState(); m_Gump.Session[((ICommitGumpEntity)this).ID] = m_State; m_State.SetValue("Type", GuardPost.GuardType); KinCityData data = KinCityManager.GetCityData(GuardPost.City); if (data == null) { return; } KinCityData.BeneficiaryData bdata = data.BeneficiaryDataList.Find(delegate(KinCityData.BeneficiaryData b) { return(b.Pm == GuardPost.Owner); }); if (bdata == null && m_Gump.From.AccessLevel <= AccessLevel.Player) { return; } m_State.SetValue("Slots", GetSlotsAvailable()); m_State.SetValue("Target", GuardPost.FightMode); m_State.SetValue("Speed", GuardPost.HireSpeed); } }
/// <summary> /// Commit any outstanding changes /// </summary> /// <param name="sender"></param> void ICommitGumpEntity.CommitChanges() { if (!((ICommitGumpEntity)this).Validate()) { m_Gump.From.SendMessage("The guard post has been changed since you were modifying it. Please make the changes again."); return; } if (m_State.IsValueDirty <KinFactionGuardTypes>("Type")) { //set guard type //TODO: - check some delay? GuardPost.GuardType = (KinFactionGuardTypes)m_State.GetValue <KinFactionGuardTypes>("Type"); m_Gump.From.SendMessage("Guard type changed to {0}.", KinSystem.GetEnumTypeDescription <KinFactionGuardTypes>((KinFactionGuardTypes)m_State.GetValue <KinFactionGuardTypes>("Type"))); } if (m_State.IsValueDirty <KinGuardPost.HireSpeeds>("Speed")) { GuardPost.HireSpeed = (KinGuardPost.HireSpeeds)m_State.GetValue <KinGuardPost.HireSpeeds>("Speed"); m_Gump.From.SendMessage("Hire rate successfully changed to {0}", KinSystem.GetEnumTypeDescription <KinGuardPost.HireSpeeds>((KinGuardPost.HireSpeeds)m_State.GetValue <KinGuardPost.HireSpeeds>("Speed"))); GuardPost.RefreshNextSpawnTime(); } if (m_State.IsValueDirty <int>("Slots")) { KinFactionGuardTypes currentType = (KinFactionGuardTypes)m_State.GetOriginalValue <KinFactionGuardTypes>("Type"); KinFactionGuardTypes type = (KinFactionGuardTypes)m_State.GetValue <KinFactionGuardTypes>("Type"); int cost = KinSystem.GetGuardCostType(type); int currentCost = KinSystem.GetGuardCostType(currentType); int slots = 0; slots += (currentCost - cost); KinCityData data = KinCityManager.GetCityData(GuardPost.City); if (data == null) { return; } KinCityData.BeneficiaryData bd = data.GetBeneficiary(GuardPost.Owner); if (bd == null) { return; } bd.ModifyGuardSlots(slots); m_Gump.From.SendMessage("Unassigned guard slots modified by {0}.", slots); } /* * if (m_State.StyleChanged) * { * //Assign new style * GuardPost.FightStyle = m_State.Style; * } */ if (m_State.IsValueDirty <FightMode>("Target")) { //Dont overwrite this one // 0 the strongest, weakest, closest //NAND out the options so these bits are all 0 GuardPost.FightMode &= ~FightMode.Strongest; GuardPost.FightMode &= ~FightMode.Weakest; GuardPost.FightMode &= ~FightMode.Closest; //write new version GuardPost.FightMode |= (FightMode)m_State.GetValue <FightMode>("Target"); m_Gump.From.SendMessage("Guard target priority successfully changed."); GuardPost.UpdateExisitngGuards(); } }