public override void Update(GameTime gameTime) { if (!castingSpell) { base.Update(gameTime); if (nameWindow != null) { nameWindow.Update(gameTime); if (nameWindow.CheckForExit()) { usedSpell = null; nameWindow = null; return; } var chara = nameWindow.GetPlayerCharacter(); if (chara != null) { for (int b = 0; b < usedSpell.BattleAction.actionEffects.Count; b++) { usedSpell.BattleAction.actionEffects[b].DoAction(null, pc.BattleStats, chara.BattleStats); } if (usedSpell.BattleAction.sounds.Length == 3) { game.Audio.PlaySound(usedSpell.BattleAction.sounds[2], true); } else { game.Audio.PlaySound(usedSpell.BattleAction.sounds[1], true); } pc.BattleStats.SP -= usedSpell.ManaCost(pc); usedSpell = null; nameWindow = null; return; } } if (usages.Contains(Usage.World) && usedSpell == null) { usedSpell = GetSpell(); if (usedSpell != null) { if (usedSpell.Usage == Usage.World || usedSpell.Usage == Usage.BothAsynchrous) { castingSpell = true; } else if (usedSpell.Usage == Usage.BothSame) { if (usedSpell.BattleAction.targetType == BattleAction.TargetType.All) { for (int i = 0; i < game.party.ActiveCharacters.Count; i++) { for (int b = 0; b < usedSpell.BattleAction.actionEffects.Count; b++) { usedSpell.BattleAction.actionEffects[b].DoAction(null, pc.BattleStats, game.party.GetPlayerCharacter(game.party.ActiveCharacters[i]).BattleStats); } } if (usedSpell.BattleAction.sounds.Length == 3) { game.Audio.PlaySound(usedSpell.BattleAction.sounds[2], true); } else { game.Audio.PlaySound(usedSpell.BattleAction.sounds[1], true); } pc.BattleStats.SP -= usedSpell.ManaCost(pc); usedSpell = null; } else { nameWindow = new NameWindow(game, new Point(TopLeft.X + 28, TopLeft.Y + 231)); } } } } if (nameWindow == null) { for (int i = 0; i < spells.Length; i++) { if (usages.Contains(pc.Spells[i].Usage)) { spells[i].Update(gameTime); } } } } else { if (usedSpell.UseEffect is RevealHiddenObjects) { usedSpell.UseEffect = new RevealHiddenObjects(game, (Map)game.Scene, ""); usedSpell.UseEffect.UseEffects(); game.CloseUIWindow(); } if (usedSpell.UseEffect is CustomEventEffect) { usedSpell.UseEffect = new CustomEventEffect(game, (Map)game.Scene, ((CustomEventEffect)usedSpell.UseEffect).eventFile); } if (usedSpell.UseEffect is FleeDungeon) { usedSpell.UseEffect.UseEffects(); game.CloseUIWindow(); } for (int i = 0; i < entities.Count; i++) { Rectangle rectangle = entities[i].Sprite.DrawnBounds; if (entities[i].Sprite.OriginMode == Sprite.OriginType.BottomMiddle) { rectangle = new Rectangle(rectangle.X - (entities[i].Sprite.SpriteSize.X / 2), rectangle.Y - entities[i].Sprite.SpriteSize.Y, rectangle.Width, rectangle.Height); } if (game.Input.HasMouseClickedOnRectangle(rectangle, true, false)) { if (entities[i].HasSpellCastEvents) { if (usedSpell.UseEffect is SpellTriggeredEvent) { var ue = (SpellTriggeredEvent)usedSpell.UseEffect; if (entities[i].GetEvents(ue.spellCond) != null) { var map = (Map)game.Scene; game.CloseUIWindow(); map.FaceEntity((Walker)map.GetEntityFromName("ENT_" + pc.Name.ToUpperInvariant()), entities[i]); map.EventManager.SetEvents(entities[i].GetEvents(ue.spellCond)); map.EventManager.DoEvent(); pc.BattleStats.SP -= usedSpell.ManaCost(pc); return; } } } if (entities[i] is Walker) { var walker = (Walker)entities[i]; if (usedSpell.UseEffect is BlindEntity && walker.Behaviour is EyeRotate) { game.CloseUIWindow(); usedSpell.UseEffect = new BlindEntity(game, (Map)game.Scene, walker, "ENT_" + pc.Name.ToUpper()); pc.BattleStats.SP -= usedSpell.ManaCost(pc); usedSpell.UseEffect.UseEffects(); return; } if (usedSpell.UseEffect is AggroEffect && walker.Behaviour is EnemyBehaviour) { game.CloseUIWindow(); usedSpell.UseEffect = new AggroEffect(game, (Map)game.Scene, "ENT_" + pc.Name.ToUpper(), walker); pc.BattleStats.SP -= usedSpell.ManaCost(pc); usedSpell.UseEffect.UseEffects(); return; } } else { if (usedSpell.UseEffect is LightTorch && entities[i].EntBehaviour is LightableTorch) { game.CloseUIWindow(); usedSpell.UseEffect = new LightTorch(game, (Map)game.Scene, entities[i], "ENT_" + pc.Name.ToUpper()); pc.BattleStats.SP -= usedSpell.ManaCost(pc); usedSpell.UseEffect.UseEffects(); return; } } } } if (game.Input.IsMouseButtonReleased()) { usedSpell = null; castingSpell = false; } } }
public override void Update(GameTime gameTime) { base.Update(gameTime); var baseOffset = new Vector2(64, 96); var recs = new Rectangle[pc.Inventory.Count]; var drawVector = new Vector2(TopLeft.X + 23, TopLeft.Y + 153); if (displayNameWindow) { NameWindow.Update(gameTime); drawHighlight = false; bool removeItem = false; if (NameWindow != null) { var chara = NameWindow.GetPlayerCharacter(); if (givenItemIndex != -1) { if (chara != null) { chara.Inventory.Add(pc.Inventory[givenItemIndex]); pc.RemoveItemFromInventory(givenItemIndex); givenItemIndex = -1; displayNameWindow = false; drawHighlight = true; NameWindow = null; return; } } if (usedItemIndex != -1) { var item = (ConsumableItem)usedItem; if (item.Usage == Usage.BothSame) { if (chara != null) { for (int b = 0; b < item.BattleAction.actionEffects.Count; b++) { item.BattleAction.actionEffects[b].DoAction(null, chara.BattleStats, chara.BattleStats); } if (item.BattleAction.sounds.Length == 3) { game.Audio.PlaySound(item.BattleAction.sounds[2], true); } else { game.Audio.PlaySound(item.BattleAction.sounds[1], true); } removeItem = true; } } else if (item.Usage == Usage.BothAsynchrous || item.Usage == Usage.World) { if (item.UseEffect is FleeDungeon) { item.UseEffect = new FleeDungeon(game); game.CloseUIWindow(); item.UseEffect.UseEffects(); removeItem = true; } if (item.UseEffect is CustomEventEffect) { item.UseEffect = new CustomEventEffect(game, (Map)game.Scene, ((CustomEventEffect)item.UseEffect).eventFile); game.CloseUIWindow(); item.UseEffect.UseEffects(); removeItem = true; } } if (removeItem) { if (!item.Reusable) { pc.RemoveItemFromInventory(usedItemIndex); } usedItemIndex = -1; drawHighlight = true; NameWindow = null; displayNameWindow = false; drawHighlight = true; usedItem = null; return; } } } if (NameWindow.CheckForExit()) { usedItem = null; usedItemIndex = -1; displayNameWindow = false; drawHighlight = true; return; } } if (!inBattle && displayNameWindow == false && draggedItemIndex == -1) { usedItemIndex = GetItemNumber(); if (usedItemIndex != -1) { usedItem = pc.Inventory[usedItemIndex]; drawHighlight = false; if (usedItem is EquippableItem) { pc.EquipItem(usedItemIndex); usedItemIndex = -1; drawHighlight = true; usedItem = null; } else if (usedItem is BookItem) { usedItem = null; usedItemIndex = -1; drawHighlight = true; } else if (usedItem is ConsumableItem) { if (NameWindow == null) { NameWindow = new NameWindow(game, new Point(TopLeft.X + 28, TopLeft.Y + 231)); } displayNameWindow = true; } //for items that do noooothing; else { drawHighlight = true; usedItem = null; } } } if (!displayNameWindow) { for (int i = 0; i < recs.Length; i++) { recs[i].X = (int)drawVector.X; recs[i].Y = (int)drawVector.Y; recs[i].Width = 67; recs[i].Height = 67; drawVector.X += 67; if (i == 3) { drawVector.X = TopLeft.X + 23; drawVector.Y = TopLeft.Y + 220; } if (i == 7) { drawVector.X = TopLeft.X + 23; drawVector.Y = TopLeft.Y + 287; } if (i == 11) { drawVector.X = TopLeft.X + 23; drawVector.Y = TopLeft.Y + 354; } } if (!dragAndDropActive) { for (int i = 0; i < recs.Length; i++) { if (game.Input.IsMouseOver(recs[i]) && game.Input.IsMouseButtonPressed()) { var newMousePos = new Vector2(game.Input.oldMouseState.X, game.Input.oldMouseState.Y); if (Vector2.Distance(newMousePos, preMousePosition) > 1) { dragAndDropActive = true; draggedItemIndex = i; break; } } } } if (confirmDropItem) { var drawOffset = new Vector2(game.GetScreenWidth() / 2 - 192, game.GetScreenHeight() / 2 - 96); var confirm = new Rectangle((int)drawOffset.X + 34, (int)drawOffset.Y + 142, 150, 62); var cancel = new Rectangle((int)drawOffset.X + 200, (int)drawOffset.Y + 142, 150, 62); if (game.Input.HasMouseClickedOnRectangle(confirm)) { confirmDropItem = false; pc.RemoveItemFromInventory(droppedItemIndex); droppedItemIndex = -1; } if (game.Input.HasMouseClickedOnRectangle(cancel)) { confirmDropItem = false; droppedItemIndex = -1; } for (int i = 0; i < ConfirmButtons.Length; i++) { ConfirmButtons[i].Update(gameTime); } } } if (dragAndDropActive) { if (game.Input.IsMouseButtonReleased()) { dragAndDropActive = false; if (!inBattle) { var dropRectangle = new Rectangle(TopLeft.X + 440, TopLeft.Y + 413, 86, 50); if (game.Input.IsMouseOver(dropRectangle)) { if (pc.Inventory[draggedItemIndex] is BookItem || pc.Inventory[draggedItemIndex].Value == -1) { confirmDropItem = false; droppedItemIndex = -1; } else { droppedItemIndex = draggedItemIndex; draggedItemIndex = -1; confirmDropItem = true; } } var giveRectangle = new Rectangle(TopLeft.X + 348, TopLeft.Y + 413, 86, 50); if (game.Input.IsMouseOver(giveRectangle) && party.ActiveCharacters.Count > 1) { givenItemIndex = draggedItemIndex; draggedItemIndex = -1; displayNameWindow = true; NameWindow = new NameWindow(game, new Point(TopLeft.X + 28, TopLeft.Y + 231)); } } for (int i = 0; i < recs.Length; i++) { if (game.Input.IsMouseOver(recs[i])) { if (draggedItemIndex == i) { draggedItemIndex = -1; break; } Item temp = pc.Inventory[i]; pc.Inventory[i] = pc.Inventory[draggedItemIndex]; pc.Inventory[draggedItemIndex] = temp; draggedItemIndex = -1; droppedItemIndex = -1; drawHighlight = true; break; } } } } preMousePosition = new Vector2(game.Input.oldMouseState.X, game.Input.oldMouseState.Y); }