// clears data dictionary and recreates it from the list of data packs private void ConstructData() { // clear the data dictionary if (policyData == null) { policyData = new Dictionary <string, SocialPolicy>(); } else { policyData.Clear(); } // fill it with technologies from all the data packs foreach (SocialPolicyDataPack dp in dataPacks) { foreach (SocialPolicy p in dp.SocialPolicies) { p.Name = SocialPolicy.FormatName(p.ID); policyData.Add(p.ID, p); } foreach (SocialPolicyTree t in dp.SocialPolicyTrees) { t.Name = SocialPolicyTree.FormatName(t.ID); policyTreeData.Add(t.ID, t); } } }
private void UnlockSocialPolicy(Player player, string policyID) { // get the policy SocialPolicy policy = player.SocialPolicyInstance.GetSocialPolicy(policyID); // check if we have already unlocked it if (policy.Unlocked) { return; } // check for prereqs foreach (string prereqID in policy.Prerequisites) { SocialPolicy prereq = Controllers.Data.SocialPolicy.GetSocialPolicy(prereqID); if (prereq != null && !prereq.Unlocked) { return; // prereqs are still locked } } // try and use free social policy points if (player.FreeSocialPoliciesAvailable > 0) { policy.Unlocked = true; player.FreeSocialPoliciesAvailable--; OnPlayerUpdated(new PlayerEventArgs(player)); return; } // unlock the policy with culture const int baseCost = 25; int playerCityCount = Controllers.City.GetPlayerCities(player.InstanceID).Count; int playerPolicyCount = player.SocialPolicyInstance.GetAllSocialPolicies().Count(sp => sp.Unlocked); double cityCountMultiplier = Math.Max(1 + 0.1 * (playerCityCount - 1), 1); double exactCost = (baseCost + Math.Pow(3 * playerPolicyCount, 2.01)) * cityCountMultiplier * player.PolicyCostModifier; int finalCost = (int)Math.Floor(exactCost / 5) * 5; if (player.Culture >= finalCost) { player.Culture -= finalCost; policy.Unlocked = true; OnPlayerUpdated(new PlayerEventArgs(player)); } }
/// <summary> /// Adds a data pack to the manager /// </summary> /// <param name="stream"></param> public void AddDataPack(Stream stream) { if (stream == null) { ConsoleManager.Instance.WriteLine("Missing social policy data", MsgType.ServerWarning); return; } // load data pack SocialPolicyDataPack pack = SerializationHelper.XmlDeserialize <SocialPolicyDataPack>(stream); dataPacks.Add(pack); foreach (SocialPolicy p in pack.SocialPolicies) { p.Name = SocialPolicy.FormatName(p.ID); policyData.Add(p.ID, p); } foreach (SocialPolicyTree t in pack.SocialPolicyTrees) { t.Name = SocialPolicyTree.FormatName(t.ID); policyTreeData.Add(t.ID, t); } }
/// <summary> /// Opens the gui element /// </summary> public void Show() { lock (SceneGame._lock_guiDrawCall) { // setup the form sceneGame.HideForms(); canvas.RemoveChild(form); form = new Form(formConfig, canvas); form.Draggable = false; form.Drawn += Form_Drawn; form.CentreControl(); form.Location = new Point(form.Location.X, 35); // get and setup the form elements ScrollBox sbSocialPolicyTrees = (ScrollBox)form.GetChildByName("sbSocialPolicyTrees"); sbSocialPolicyTrees.SelectedIndex = selectedIndex; sbSocialPolicyTrees.Items = GetPolicyTreeListItems(); sbSocialPolicyTrees.SelectedChanged += SbPolicyTrees_SelectedChanged; PolicyTreeListItem selectedItem = (PolicyTreeListItem)sbSocialPolicyTrees.Selected; lines = new List <Line>(); int offsetX = sbSocialPolicyTrees.AbsoluteBounds.Width + 10; int offsetY = 50; int itemWidth = 200; int itemHeight = 70; int sepX = 70; int sepY = 50; // build a button for every node in the social policy tree foreach (SocialPolicy policy in client.Player.SocialPolicyInstance.GetAllSocialPoliciesInTree(selectedItem.SocialPolicyTree.ID)) { Rectangle dest = new Rectangle(offsetX + policy.GridX * (itemWidth + sepX), offsetY + policy.GridY * (itemHeight + sepY), itemWidth, itemHeight); Button b = new Button(dest, form); string text = policy.Name; // format the button text b.Text = text.ToRichText(); // pick an appropriate sprite bool unlockable = true; foreach (string prereqID in policy.Prerequisites) { SocialPolicy prereq = client.Player.SocialPolicyInstance.GetSocialPolicy(prereqID); if (prereq != null && !prereq.Unlocked) { unlockable = false; } } if (policy.Unlocked) { b.Sprite = policyUnlockedSprite; } else if (unlockable) { b.Sprite = policyAdoptable; } else { b.Sprite = policyLockedSprite; } string policyID = policy.ID; // cache id because of closure b.MouseClick += (s, a) => { // only tell the server to select a new tech if all the prereqs are unlocked SocialPolicy clicked = client.DataManager.SocialPolicy.GetSocialPolicy(policyID); foreach (string prereqID in clicked.Prerequisites) { SocialPolicy prereq = client.Player.SocialPolicyInstance.GetSocialPolicy(prereqID); if (prereq != null && !prereq.Unlocked) { return; } } client.CommandPlayer(new PlayerCommand(PlayerCommandID.UnlockPolicy, policyID)); }; // add a tool tip with more info about the policy b.ToolTip = new ToolTip(policy.Description.ToRichText(), 500); b.ToolTip.FollowCurosr = true; // add a line from the current policy to all its prereqs foreach (string prereqID in policy.Prerequisites) { SocialPolicy prereq = client.DataManager.SocialPolicy.GetSocialPolicy(prereqID); if (prereq == null) { continue; } Rectangle prereqRect = new Rectangle(offsetX + prereq.GridX * (itemWidth + sepX), offsetY + prereq.GridY * (itemHeight + sepY), itemWidth, itemHeight); lines.Add(new Line(new Vector2(form.AbsoluteLocation.X + dest.X, dest.Y + itemHeight / 2 + offsetY), new Vector2(form.AbsoluteLocation.X + prereqRect.X + itemWidth, prereqRect.Y + itemHeight / 2 + offsetY))); } } } }