void OnMouseDown() { if (alive == false) { return; } else { if (awake == false) { menu_holder.GetComponent <CanvasGroup>().alpha = 1f; awake = true; StatSelector.SetName(gameObject.tag); if (gameObject.tag == "GoldMine") { StatSelector.SetGold(2); StatSelector.SetSprite(sprite); StatSelector.SetPrice(g.build_cost / 2); } else if (gameObject.tag == "missileresearch") { StatSelector.SetNumber(ReturnMissileLength() * 5); StatSelector.SetSprite(sprite); StatSelector.SetPrice(g.research_cost / 2); } else if (gameObject.tag == "lightresearch") { StatSelector.SetNumber(ReturnLightLength() * 5); StatSelector.SetSprite(sprite); StatSelector.SetPrice(g.research_cost / 2); } else if (gameObject.tag == "slowresearch") { StatSelector.SetNumber(ReturnLaserLength() * 2); StatSelector.SetSprite(sprite); StatSelector.SetPrice(g.research_cost / 2); } else if (gameObject.tag == "Explorer") { StatSelector.ExploreInfo(); StatSelector.SetSprite(sprite); } else { StatSelector.SetDamage(returnDPS()); StatSelector.SetPrice(g.turr_cost / 2); } print("hello"); } else { menu_holder.GetComponent <CanvasGroup>().alpha = 0f; awake = false; } } }
public float returnDPS() { StatSelector.SetSprite(sprite); if (gameObject.tag == "LightGun") { return(gameObject.GetComponent <Turret>().returnDamage()); } else if (gameObject.tag == "Laser") { return(gameObject.GetComponent <Turret>().damageOT); } else if (gameObject.tag == "Missile") { return(gameObject.GetComponent <Turret>().returnDamage()); } return(0); }
/// <summary> /// decreases the stat that the button targets, by the global incremental delta /// </summary> public void DecreaseCurrentStat(Button btn) { StatSelector targetStat = (StatSelector)btn.payload; if (targetStat == null) { return; } if (targetStat.current - ATTR_POINTS_DELTA < 0) { return; } availablePoints += ATTR_POINTS_DELTA; targetStat.current -= ATTR_POINTS_DELTA; }
/// <summary> /// Increments the stat that the button targets, by the global incremental delta /// </summary> public void IncreaseCurrentStat(Button btn) { StatSelector targetStat = (StatSelector)btn.payload; if (targetStat == null) { return; } if (availablePoints - ATTR_POINTS_DELTA < 0 || targetStat.current + ATTR_POINTS_DELTA > MAX_ATTR_LEVEL) { return; } availablePoints -= ATTR_POINTS_DELTA; targetStat.current += ATTR_POINTS_DELTA; }
// permament features public override void InitializeConsole() { const int topY = 12; const int left = 3; base.InitializeConsole(); // back button buttons.Add(new Button(console.getWidth() - 10, 1, 6, 1, "[back]", elementDark, Constants.COL_BLUE, foregroundColor, GotoMainMenu)); // start game button buttons.Add(new Button(console.getWidth() - 10, console.getHeight() - 2, 6, 1, "[done]", elementDark, Constants.COL_BLUE, foregroundColor, StartGame)); // TODO: change to load level // init some temp components to store data in -------------------------------------------------------- Attribute buttons stuff attributes = new AttributesComponent(); // init the stat adjusting buttons for each stat attrSelectors = new List <StatSelector>(); int buttonLine = 0; foreach (string attr in attributes.Attributes()) { int y = buttonLine + topY; const int leftOffset = 14; StatSelector statSelector = new StatSelector(); statSelector.statName = attr; statSelector.current = 0; // the decrease button statSelector.decrease = new Button(left + leftOffset, y, 1, 1, "-", elementDark, Constants.COL_BLUE, foregroundColor, DecreaseCurrentStat); statSelector.decrease.payload = statSelector; // the increase button statSelector.increase = new Button(left + leftOffset + 6, y, 1, 1, "+", elementDark, Constants.COL_BLUE, foregroundColor, IncreaseCurrentStat); statSelector.increase.payload = statSelector; buttons.Add(statSelector.decrease); buttons.Add(statSelector.increase); attrSelectors.Add(statSelector); buttonLine += 2; } const string mainTitle = "[CREATE CHARACTER]"; // draw main title DrawText(console.getWidth() / 2 - mainTitle.Length / 2, 1, mainTitle, foregroundColor); DrawDividerLine(0, 2, console.getWidth()); // draw out the attibute names in a list DrawText(left, 4, "Character Name:", Constants.COL_ATTENTION); DrawText(left, topY - 4, "Character Attrbiutes: ", Constants.COL_ATTENTION); // initialize the default skill and item lists ----------------------------------------------------- Item and skill selection stuff defaultSkills = new List <Entity>(); defaultItems = new List <Entity>(); equippedSkills = new List <Entity>(); equippedItems = new List <Entity>(); string[] skillNames = engine.dataTables.GetListValue("startSkills", "CharacterCreation", "set"); string[] itemNames = engine.dataTables.GetListValue("startItems", "CharacterCreation", "set"); // The skill selector area --------------------------------------------------------- const int skillLeft = 30; const int tableY = 4; const int tableWidth = 32; // define a littel subsection box for the skill select area skillSelectSection = new SubSection(); skillSelectSection.origin = new Vector2(skillLeft - 1, tableY + 1); skillSelectSection.size = new Vector2(tableWidth, 43); skillDropSection = new SubSection(); skillDropSection.origin = new Vector2(skillLeft - 1, skillSelectSection.origin.Y + skillSelectSection.size.Y + 3); skillDropSection.size = new Vector2(tableWidth, 7); DrawText(skillSelectSection.origin.X, skillSelectSection.origin.Y - 1, "Starting Skills:", Constants.COL_ATTENTION); DrawText(skillDropSection.origin.X, skillDropSection.origin.Y - 1, "Equipped Skills:", Constants.COL_ATTENTION); int line = 0; // for each skill in the list from data, instantiate the skill antity and create a hover target for it foreach (string name in skillNames) { Entity skill = engine.data.InstantiateEntity(name); defaultSkills.Add(skill); var getName = (EGetScreenName)skill.FireEvent(new EGetScreenName()); int y = tableY + 2 + line; //DrawText(skillLeft, y, "+" + getName.text, foregroundColor); // create a hover target for each skill Hoverable hoverTarget = new Hoverable(); hoverTarget.entity = skill; hoverTarget.width = getName.text.Length + 1; hoverTarget.origin = new Vector2(skillSelectSection.origin.X + 1, y); hoverTarget.handler = OpenSkillInspector; hoverableItems.Add(hoverTarget); line += 1; } // The item selector area --------------------------------------------------------- const int itemLeft = 63; itemSelectSection = new SubSection(); itemSelectSection.origin = new Vector2(itemLeft - 1, tableY + 1); itemSelectSection.size = new Vector2(tableWidth, 43); itemDropSection = new SubSection(); itemDropSection.origin = new Vector2(itemLeft - 1, itemSelectSection.origin.Y + itemSelectSection.size.Y + 3); itemDropSection.size = new Vector2(tableWidth, 7); DrawText(itemSelectSection.origin.X, itemSelectSection.origin.Y - 1, "Starting Items:", Constants.COL_ATTENTION); DrawText(itemDropSection.origin.X, itemDropSection.origin.Y - 1, "Equipped Items:", Constants.COL_ATTENTION); line = 0; // for each item in the list from data, instantiate the item entity and create a hover target for it foreach (string name in itemNames) { Entity item = engine.data.InstantiateEntity(name); defaultItems.Add(item); var getName = (EGetScreenName)item.FireEvent(new EGetScreenName()); int y = tableY + 2 + line; //DrawText(itemLeft, y, "+" + getName.text, foregroundColor); // create a hover target for each skill Hoverable hoverTarget = new Hoverable(); hoverTarget.entity = item; hoverTarget.width = getName.text.Length + 1; hoverTarget.origin = new Vector2(itemSelectSection.origin.X + 1, y); hoverTarget.handler = OpenItemInspector; hoverableItems.Add(hoverTarget); line += 1; } }
/// <summary> /// Read stats from a serialised byte array /// </summary> /// <param name="bitBuffer">The current buffer state.</param> /// <param name="stats">The stats block to populate.</param> /// <param name="readNameCount">TODO</param> public void ReadStats(BitBuffer bitBuffer, UnitObjectStats stats, bool readNameCount = false) { stats._version = bitBuffer.ReadBits(16); stats.Context = (StatContext)bitBuffer.ReadBits(3); if (_debugOutputLoadingProgress) { Debug.WriteLine(String.Format("stats.Version = {0}, stats.Context = {1} (0x{2:X2})", stats._version, stats.Context, (int)stats.Context)); } if (stats._version != 0x0A) { throw new Exceptions.NotSupportedVersionException("0x0A", "0x" + stats._version.ToString("X2")); } int statSelectorCount = bitBuffer.ReadBits(6); if (_debugOutputLoadingProgress) { Debug.WriteLine(String.Format("stats.StatSelectorCount = {0}", statSelectorCount)); } for (int i = 0; i < statSelectorCount; i++) { StatSelector statSelector = new StatSelector(); if (stats.Context == StatContext.UseRows) { statSelector.RowIndex = bitBuffer.ReadBits(5); statSelector.StatSelectorRow = (ExcelTablesRow)_fileManager.GetRowFromIndex(Xls.TableCodes.STATS_SELECTOR, statSelector.RowIndex); // StatsSelector table } else { statSelector.Code = bitBuffer.ReadUInt16(); statSelector.StatSelectorRow = (ExcelTablesRow)_fileManager.GetRowFromCode(Xls.TableCodes.STATS_SELECTOR, (short)statSelector.Code); // StatsSelector table } int selectorStatCount = bitBuffer.ReadInt16(); if (_debugOutputLoadingProgress) { Debug.WriteLine(String.Format("StatSelectors[{0}].Name = {1}, .Code = 0x{2:X4}, .RowIndex = {3}, .StatCount = {4}", i, statSelector.Name, statSelector.Code, statSelector.RowIndex, selectorStatCount)); } for (int j = 0; j < selectorStatCount; j++) { Stat stat = _ReadStat(bitBuffer, stats); statSelector.Stats.Add(stat); } stats.StatSelectors.Add(statSelector); } int statCount = bitBuffer.ReadBits(16); if (_debugOutputLoadingProgress) { Debug.WriteLine(String.Format("stats.StatCount = {0}", statCount)); } for (int i = 0; i < statCount; i++) { Stat stat = _ReadStat(bitBuffer, stats); stats.Stats[stat.StatRow.code] = stat; } if (!readNameCount) return; stats.NameCount = bitBuffer.ReadBits(8); if (_debugOutputLoadingProgress) { Debug.WriteLine(String.Format("stats.NameCount = {0}", stats.NameCount)); } for (int i = 0; i < stats.NameCount; i++) { StatName name = new StatName { Unknown1 = (short)bitBuffer.ReadBits(5), Stats = new UnitObjectStats(_fileManager, _version) }; if (_debugOutputLoadingProgress) { Debug.WriteLine(String.Format("stats.Unknown1 = {0}", name.Unknown1)); } ReadStats(bitBuffer, name.Stats, false); stats.Names.Add(name); } }