// Add a signal to place a monster group public void AddAreaMonster(QuestData.Spawn m) { Game game = Game.Get(); Sprite tileSprite; Texture2D newTex = Resources.Load("sprites/target") as Texture2D; // Check load worked if (newTex == null) { ValkyrieDebug.Log("Error: Cannot load monster image"); Application.Quit(); } // Create object GameObject gameObject = new GameObject("MonsterSpawn"); gameObject.tag = Game.DIALOG; gameObject.transform.SetParent(game.tokenCanvas.transform); // Create the image UnityEngine.UI.Image image = gameObject.AddComponent <UnityEngine.UI.Image>(); tileSprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1); image.color = Color.red; image.sprite = tileSprite; image.rectTransform.sizeDelta = new Vector2(1f, 1f); // Move to square (105 units per square) gameObject.transform.Translate(new Vector3(m.location.x, m.location.y, 0), Space.World); // Add pulser gameObject.AddComponent <SpritePulser>(); }
public MonsterEvent(string name) : base(name) { // cast the monster event qMonster = qEvent as QuestData.Spawn; // monsters are generated on the fly to avoid duplicate for D2E when using random }
public void GenerateMonsterSelection() { // Determine monster types bool progress = false; bool force = false; bool done = false; while (!done) { progress = false; foreach (KeyValuePair <string, QuestData.QuestComponent> kv in qd.components) { QuestData.Spawn qs = kv.Value as QuestData.Spawn; if (qs != null) { progress |= AttemptMonsterMatch(qs, force); if (progress && force) { force = false; } } } if (!progress && !force) { force = true; } else if (!progress && force) { done = true; } } }
public EditorComponentSpawnPlacement(string nameIn) : base() { Game game = Game.Get(); monsterComponent = game.quest.qd.components[nameIn] as QuestData.Spawn; component = monsterComponent; name = component.sectionName; Update(); }
public MonsterEvent(string name) : base(name) { // cast the monster event qMonster = qEvent as QuestData.Spawn; if (!game.quest.monsterSelect.ContainsKey(qMonster.sectionName)) { ValkyrieDebug.Log("Warning: Monster type unknown in event: " + qMonster.sectionName); return; } string t = game.quest.monsterSelect[qMonster.sectionName]; if (game.quest.qd.components.ContainsKey(t)) { cMonster = new QuestMonster(game.quest.qd.components[t] as QuestData.CustomMonster); } else { cMonster = game.cd.monsters[t]; } }
override public float AddSubEventComponents(float offset) { spawnComponent = component as QuestData.Spawn; UIElement ui = null; if (game.gameType is D2EGameType) { ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(0, offset, 6, 1); ui.SetText(new StringKey("val", "X_COLON", MONSTER_UNIQUE)); if (!spawnComponent.unique) { ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(6, offset, 3, 1); ui.SetText(CommonStringKeys.FALSE); ui.SetButton(delegate { UniqueToggle(); }); new UIElementBorder(ui); offset += 2; } else { ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(6, offset, 3, 1); ui.SetText(CommonStringKeys.TRUE); ui.SetButton(delegate { UniqueToggle(); }); new UIElementBorder(ui); offset += 2; ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(0, offset, 5, 1); ui.SetText(new StringKey("val", "X_COLON", UNIQUE_TITLE)); uniqueTitleUIE = new UIElementEditable(Game.EDITOR, scrollArea.GetScrollTransform()); uniqueTitleUIE.SetLocation(5, offset, 14.5f, 1); uniqueTitleUIE.SetText(spawnComponent.uniqueTitle.Translate()); uniqueTitleUIE.SetSingleLine(); uniqueTitleUIE.SetButton(delegate { UpdateUniqueTitle(); }); new UIElementBorder(uniqueTitleUIE); offset += 2; ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(0, offset++, 20, 1); ui.SetText(new StringKey("val", "X_COLON", UNIQUE_INFO)); uniqueTextUIE = new UIElementEditablePaneled(Game.EDITOR, scrollArea.GetScrollTransform()); uniqueTextUIE.SetLocation(0.5f, offset, 19, 18); uniqueTextUIE.SetText(spawnComponent.uniqueText.Translate()); offset += uniqueTextUIE.HeightToTextPadding(1); uniqueTextUIE.SetButton(delegate { UpdateUniqueText(); }); new UIElementBorder(uniqueTextUIE); offset += 1; } } ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(0, offset, 5, 1); ui.SetText(new StringKey("val", "X_COLON", HEALTH)); healthUIE = new UIElementEditable(Game.EDITOR, scrollArea.GetScrollTransform()); healthUIE.SetLocation(5, offset, 3, 1); healthUIE.SetText(spawnComponent.uniqueHealthBase.ToString()); healthUIE.SetSingleLine(); healthUIE.SetButton(delegate { UpdateHealth(); }); new UIElementBorder(healthUIE); ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(8, offset, 7, 1); ui.SetText(new StringKey("val", "X_COLON", HEALTH_HERO)); healthHeroUIE = new UIElementEditable(Game.EDITOR, scrollArea.GetScrollTransform()); healthHeroUIE.SetLocation(15, offset, 3, 1); healthHeroUIE.SetText(spawnComponent.uniqueHealthHero.ToString()); healthHeroUIE.SetSingleLine(); healthHeroUIE.SetButton(delegate { UpdateHealthHero(); }); new UIElementBorder(healthHeroUIE); offset += 2; ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(1.5f, offset, 17, 1); ui.SetText(new StringKey("val", "X_COLON", TYPES)); ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(18.5f, offset++, 1, 1); ui.SetText(CommonStringKeys.PLUS, Color.green); ui.SetButton(delegate { MonsterTypeAdd(0); }); new UIElementBorder(ui, Color.green); int i = 0; for (i = 0; i < spawnComponent.mTypes.Length; i++) { int mSlot = i; string mName = spawnComponent.mTypes[i]; if (mName.IndexOf("Monster") == 0) { mName = mName.Substring("Monster".Length); } if ((spawnComponent.mTypes.Length > 1) || (spawnComponent.mTraitsRequired.Length > 0) || (spawnComponent.mTraitsPool.Length > 0)) { ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(0.5f, offset, 1, 1); ui.SetText(CommonStringKeys.MINUS, Color.red); ui.SetButton(delegate { MonsterTypeRemove(mSlot); }); new UIElementBorder(ui, Color.red); } ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); if (game.quest.qd.components.ContainsKey(spawnComponent.mTypes[i])) { ui.SetLocation(1.5f, offset, 16, 1); UIElement link = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); link.SetLocation(17.5f, offset, 1, 1); link.SetText("<b>⇨</b>", Color.cyan); link.SetTextAlignment(TextAnchor.LowerCenter); link.SetButton(delegate { QuestEditorData.SelectComponent(spawnComponent.mTypes[mSlot]); }); new UIElementBorder(link, Color.cyan); } else { ui.SetLocation(1.5f, offset, 17, 1); } ui.SetText(mName); ui.SetButton(delegate { MonsterTypeReplace(mSlot); }); new UIElementBorder(ui); ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(18.5f, offset++, 1, 1); ui.SetText(CommonStringKeys.PLUS, Color.green); ui.SetButton(delegate { MonsterTypeAdd(mSlot + 1); }); new UIElementBorder(ui, Color.green); } offset++; float traitOffset = offset; ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(0.5f, offset, 8, 1); ui.SetText(REQ_TRAITS); ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(8.5f, offset++, 1, 1); ui.SetText(CommonStringKeys.PLUS, Color.green); ui.SetButton(delegate { MonsterTraitsAdd(); }); new UIElementBorder(ui, Color.green); for (i = 0; i < spawnComponent.mTraitsRequired.Length; i++) { int mSlot = i; string mName = spawnComponent.mTraitsRequired[i]; if ((spawnComponent.mTypes.Length > 0) || (spawnComponent.mTraitsRequired.Length > 1) || (spawnComponent.mTraitsPool.Length > 0)) { ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(0.5f, offset, 1, 1); ui.SetText(CommonStringKeys.MINUS, Color.red); ui.SetButton(delegate { MonsterTraitsRemove(mSlot); }); new UIElementBorder(ui, Color.red); } ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(1.5f, offset++, 8, 1); ui.SetText(new StringKey("val", mName)); ui.SetButton(delegate { MonsterTraitReplace(mSlot); }); new UIElementBorder(ui); } ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(10.5f, traitOffset, 8, 1); ui.SetText(POOL_TRAITS); ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(18.5f, traitOffset++, 1, 1); ui.SetText(CommonStringKeys.PLUS, Color.green); ui.SetButton(delegate { MonsterTraitsAdd(true); }); new UIElementBorder(ui, Color.green); for (int j = 0; j < spawnComponent.mTraitsPool.Length; j++) { int mSlot = j; string mName = spawnComponent.mTraitsPool[j]; if ((spawnComponent.mTypes.Length > 0) || (spawnComponent.mTraitsRequired.Length > 0) || (spawnComponent.mTraitsPool.Length > 1)) { ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(10.5f, traitOffset, 1, 1); ui.SetText(CommonStringKeys.MINUS, Color.red); ui.SetButton(delegate { MonsterTraitsRemove(mSlot, true); }); new UIElementBorder(ui, Color.red); } ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(11.5f, traitOffset++, 8, 1); ui.SetText(new StringKey("val", mName)); ui.SetButton(delegate { MonsterTraitReplace(mSlot, true); }); new UIElementBorder(ui); } if (traitOffset > offset) { offset = traitOffset; } offset++; if (game.gameType is D2EGameType || game.gameType is IAGameType) { offset = AddPlacementComponenets(offset); } return(offset); }
public bool AttemptMonsterMatch(QuestData.Spawn spawn, bool force = true) { if (monsterSelect.ContainsKey(spawn.sectionName)) { return(false); } if ((spawn.mTraitsPool.Length + spawn.mTraitsRequired.Length) == 0) { foreach (string t in spawn.mTypes) { if (monsterSelect.ContainsKey(t)) { monsterSelect.Add(spawn.sectionName, monsterSelect[t]); return(true); } if (t.IndexOf("Spawn") == 0) { return(false); } string monster = t; if (monster.IndexOf("Monster") != 0 && monster.IndexOf("CustomMonster") != 0) { monster = "Monster" + monster; } // Monster type might be a unique for this quest if (game.quest.qd.components.ContainsKey(monster)) { monsterSelect.Add(spawn.sectionName, monster); return(true); } // Monster type might exist in content packs, 'Monster' is optional else if (game.cd.monsters.ContainsKey(monster)) { monsterSelect.Add(spawn.sectionName, monster); return(true); } } } else { // List of exclusions List <string> exclude = new List <string>(); foreach (string t in spawn.mTypes) { if (monsterSelect.ContainsKey(t)) { exclude.Add(monsterSelect[t]); } else if (t.IndexOf("Spawn") == 0 && !force) { return(false); } else { exclude.Add(t); } } // Start a list of matches List <string> list = new List <string>(); foreach (KeyValuePair <string, MonsterData> kv in game.cd.monsters) { bool allFound = true; foreach (string t in spawn.mTraitsRequired) { // Does the monster have this trait? if (!kv.Value.ContainsTrait(t)) { // Trait missing, exclude monster allFound = false; } } // Must have one of these traits bool oneFound = (spawn.mTraitsPool.Length == 0); foreach (string t in spawn.mTraitsPool) { // Does the monster have this trait? if (kv.Value.ContainsTrait(t)) { oneFound = true; } } bool excludeBool = false; foreach (string t in exclude) { if (t.Equals(kv.Key)) { excludeBool = true; } } // Monster has all traits if (allFound && oneFound && !excludeBool) { list.Add(kv.Key); } } if (list.Count == 0) { ValkyrieDebug.Log("Error: Unable to find monster of traits specified in event: " + spawn.sectionName); Destroyer.MainMenu(); return(false); } // Pick monster at random from candidates monsterSelect.Add(spawn.sectionName, list[Random.Range(0, list.Count)]); return(true); } return(false); }