示例#1
0
 public void SetUp(Character character)
 {
     this.No        = character.No;
     this.Name      = character.Name;
     this.Type      = character.Type;
     this.Att       = character.Att;
     image.color    = manaIcon.ColorImage(ToAttribute(Att));
     this.Hp        = character.Hp;
     this.Atk       = character.Atk;
     this.Rec       = character.Rec;
     this.Skill     = character.Skill;
     this.SkillCost = character.SkillCost;
     mananum.text   = SkillCost.ToString();
     this.refR      = character.refR;
     this.refW      = character.refW;
     this.refL      = character.refL;
     this.refS      = character.refS;
     this.refD      = character.refD;
 }
        protected void tvSkills_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
        {
            if (e.Node.Checked)
            {
                TreeView OrigTreeView = new TreeView();
                CopyTreeNodes(tvSkills, OrigTreeView);

                MarkParentNodes(e.Node);

                List <cSkillPool> oSkillList = Session["CharacterSkillPools"] as List <cSkillPool>;

                DataTable dtPointsSpent = new DataTable();
                dtPointsSpent.Columns.Add(new DataColumn("PoolID", typeof(int)));
                dtPointsSpent.Columns.Add(new DataColumn("CPSpent", typeof(double)));
                dtPointsSpent.Columns.Add(new DataColumn("TotalCP", typeof(double)));

                foreach (cSkillPool cSkill in oSkillList)
                {
                    DataRow dNewRow = dtPointsSpent.NewRow();
                    dNewRow["PoolID"]  = cSkill.PoolID;
                    dNewRow["TotalCP"] = cSkill.TotalPoints;
                    dNewRow["CPSpent"] = 0.0;

                    dtPointsSpent.Rows.Add(dNewRow);
                }

                DataTable dtAllSkills = Session["SkillNodes"] as DataTable;
                double    TotalSpent  = 0.0;

                DataTable dtSkillCosts = new DataTable();
                dtSkillCosts.Columns.Add(new DataColumn("Skill", typeof(string)));
                dtSkillCosts.Columns.Add(new DataColumn("Cost", typeof(double)));
                dtSkillCosts.Columns.Add(new DataColumn("SortOrder", typeof(int)));
                dtSkillCosts.Columns.Add(new DataColumn("SkillID", typeof(int)));

                double TotalCP = 0.0;
                double.TryParse(Session["TotalCP"].ToString(), out TotalCP);

                string sSkills = "";
                foreach (TreeNode SkillNode in tvSkills.CheckedNodes)
                {
                    int iSkillID;
                    if (int.TryParse(SkillNode.Value, out iSkillID))
                    {
                        DataRow[] dSkillRow = dtAllSkills.Select("CampaignSkillNodeID = " + iSkillID.ToString());
                        if (dSkillRow.Length > 0)
                        {
                            double SkillCost;
                            int    PoolID;
                            if ((double.TryParse(dSkillRow[0]["SkillCPCost"].ToString(), out SkillCost)) &&
                                (int.TryParse(dSkillRow[0]["CampaignSkillPoolID"].ToString(), out PoolID)))
                            {
                                if (dtSkillCosts.Select("SkillID = " + iSkillID.ToString()).Length == 0)
                                {
                                    DataRow[] dSkillCountRow = dtPointsSpent.Select("PoolID = " + PoolID.ToString());
                                    if (dSkillCountRow.Length > 0)
                                    {
                                        dSkillCountRow[0]["CPSpent"] = (double)(dSkillCountRow[0]["CPSpent"]) + SkillCost;
                                    }
                                }
                                TotalSpent += SkillCost;
                                if (SkillCost > 0)
                                {
                                    sSkills += dSkillRow[0]["SkillName"].ToString() + ":" + SkillCost.ToString() + ", ";
                                }
                                DataRow dNewRow = dtSkillCosts.NewRow();
                                dNewRow["Skill"]     = dSkillRow[0]["SkillName"].ToString();
                                dNewRow["Cost"]      = SkillCost;
                                dNewRow["SkillID"]   = iSkillID;
                                dNewRow["SortOrder"] = 10;
                                dtSkillCosts.Rows.Add(dNewRow);
                            }
                        }
                    }
                }

                bool bSpentTooMuch = false;

                foreach (DataRow dCostRow in dtPointsSpent.Rows)
                {
                    double CPSpent;
                    double TotalCPForPool;
                    if ((double.TryParse(dCostRow["TotalCP"].ToString(), out TotalCPForPool)) &&
                        (double.TryParse(dCostRow["CPSpent"].ToString(), out CPSpent)))
                    {
                        if (CPSpent > TotalCPForPool)
                        {
                            bSpentTooMuch = true;
                        }
                    }
                }

                if (bSpentTooMuch)
                {
                    tvSkills.Nodes.Clear();
                    TreeView OrigTree = Session["CurrentSkillTree"] as TreeView;
                    CopyTreeNodes(OrigTree, tvSkills);

                    AlertMessage = "You do not have enough CP to buy that.";
                }
                else
                {
                    bMeetAllRequirements = true;
                    CheckForRequirements(e.Node.Value);
                    if (!bMeetAllRequirements)
                    {
                        tvSkills.Nodes.Clear();
                        TreeView OrigTree = Session["CurrentSkillTree"] as TreeView;
                        CopyTreeNodes(OrigTree, tvSkills);
                        e.Node.Checked = false;
                        AlertMessage   = "You do not have all the requirements to purchase that item.";
                    }
                    else
                    {
                        CheckAllNodesWithValue(e.Node.Value, true);
                    }
                }
                List <TreeNode> FoundNodes = FindNodesByValue(e.Node.Value);
                foreach (TreeNode t in FoundNodes)
                {
                    t.ShowCheckBox = false;
                    EnableChildren(t);
                }
            }
            else
            {
                // Check to see if we should not allow them to sell it back.
                if (ViewState["SkillList"] != null)
                {
                    int iSkillID;
                    if (int.TryParse(e.Node.Value, out iSkillID))
                    {
                        List <int> SkillList = ViewState["SkillList"] as List <int>;
                        if (SkillList.Contains(iSkillID))
                        {
                            if (hidAllowCharacterRebuild.Value == "0")
                            {
                                e.Node.Checked = true;
                                AlertMessage   = "This campaign is not allowing skills to be rebuilt at this time.  Once a skill is selected and saved, it cannot be changed.";
                                //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
                                //        "MyApplication",
                                //        jsString,
                                //        true);
                                return;
                            }
                        }
                    }
                }
                DeselectChildNodes(e.Node);
                CheckAllNodesWithValue(e.Node.Value, false);

                List <TreeNode> FoundNodes = FindNodesByValue(e.Node.Value);
                foreach (TreeNode t in FoundNodes)
                {
                    t.Text         = t.Text.Replace("grey", "black");
                    t.ImageUrl     = "";
                    t.ShowCheckBox = true;
                    EnableChildren(t);
                }
            }
            CheckExclusions();
            ListSkills();
            Session["CurrentSkillTree"] = tvSkills;

            lblMessage.Text      = "Skills Changed";
            lblMessage.ForeColor = Color.Red;
        }