private static void AddRegionFileMagicSprite(Character user, Magic magic, Vector2 origin, Vector2 destination, bool destroyOnEnd) { if (magic.RegionFile == null) { return; } var direction = destination - origin; var directionIndex = Utils.GetDirectionIndex(direction, 8); var items = magic.RegionFile.ContainsKey(directionIndex) ? magic.RegionFile[directionIndex] : magic.RegionFile[0]; //Make destination at tile center destination = Map.ToPixelPosition(Map.ToTilePosition(destination)); foreach (var item in items) { var magicSprite = GetFixedPositionMagicSprite(user, magic, destination + item.Offset, destroyOnEnd); if (item.Delay > 0) { AddWorkItem(new WorkItem(item.Delay, magicSprite)); } else { AddMagicSprite(magicSprite); } } }
private static void AddVTypeFixedPOsitionMagicSprite(Character user, Magic magic, Vector2 origin, Vector2 destination, bool destroyOnEnd) { var direction = destination - origin; var directionIndex = Utils.GetDirectionIndex(direction, 8); var count = 3; if (magic.CurrentLevel > 3) { count += ((magic.CurrentLevel - 1) / 3) * 2; } var orgTile = PathFinder.FindNeighborInDirection(Map.ToTilePosition(origin), directionIndex); AddMagicSprite(GetFixedPositionMagicSprite(user, magic, Map.ToPixelPosition(orgTile), destroyOnEnd)); const float magicDelayMilliseconds = 60f; var leftVTile = orgTile; var rightVTile = orgTile; for (var i = 1; i < count; i++) { leftVTile = PathFinder.FindNeighborInDirection(leftVTile, (directionIndex + 7) % 8); rightVTile = PathFinder.FindNeighborInDirection(rightVTile, (directionIndex + 1) % 8); AddWorkItem(new WorkItem(i * magicDelayMilliseconds, GetFixedPositionMagicSprite(user, magic, Map.ToPixelPosition(leftVTile), destroyOnEnd))); AddWorkItem(new WorkItem(i * magicDelayMilliseconds, GetFixedPositionMagicSprite(user, magic, Map.ToPixelPosition(rightVTile), destroyOnEnd))); } }
public void Destroy() { if (IsInDestroy) { return; } _isInDestroy = true; if (BelongMagic.MoveKind == 15) { Texture = null; _superModeDestroySprites = new LinkedList <Sprite>(); List <Character> targets; if (BelongCharacter.IsPlayer || BelongCharacter.IsFighterFriend) { targets = NpcManager.NpcsInView.Where(npc => npc.IsEnemy).Cast <Character>().ToList(); } else { targets = NpcManager.NpcsInView.Where(npc => npc.IsFighterFriend).Cast <Character>().ToList(); targets.Add(Globals.ThePlayer); } foreach (var character in targets) { AddDestroySprite(_superModeDestroySprites, character.PositionInWorld, BelongMagic.VanishImage, BelongMagic.VanishSound); CharacterHited(character); character.NotifyEnemyAndAllNeighbor(BelongCharacter); } if (_superModeDestroySprites.Count == 0) { _isDestroyed = true; } } else if (BelongMagic.MoveKind == 23) { //Time stop if (Globals.TheGame.TimeStoperMagicSprite == this) { Globals.TheGame.TimeStoperMagicSprite = null; } } else { switch (BelongMagic.MoveKind) { case 20: { BelongCharacter.IsInTransport = false; var tilePosition = Map.ToTilePosition(_destnationPixelPosition); var finded = PathFinder.FindNonobstacleNeighborOrItself(BelongCharacter, ref tilePosition); if (finded) { //Destination has no obstacle, transport magic user. TilePosition = tilePosition; BelongCharacter.SetTilePosition(tilePosition); } } break; case 21: { var player = BelongCharacter as Player; if (player == null) { throw new Exception("Magic kind 21 internal error."); } player.EndControlCharacter(); } break; case 22: { PositionInWorld = _summonedNpc.PositionInWorld; if (_summonedNpc != null) { _summonedNpc.Death(); } } break; } if (BelongMagic.VanishImage != null) { Texture = BelongMagic.VanishImage; PlayFrames(FrameCountsPerDirection); } else { _isDestroyed = true; } SoundManager.Play3DSoundOnece(BelongMagic.VanishSound, PositionInWorld - Globals.ListenerPosition); UseExplodeMagic(); if (BelongMagic.VibratingScreen > 0) { Globals.TheCarmera.VibaratingScreen(BelongMagic.VibratingScreen); } } }
private bool Init(Magic belongMagic, Character belongCharacter, Vector2 positionInWorld, float velocity, Vector2 moveDirection, bool destroyOnEnd) { if (belongMagic == null || belongCharacter == null) { _isDestroyed = true; return(false); } if (belongMagic.NoExplodeWhenLifeFrameEnd > 0) { destroyOnEnd = false; } else if (belongMagic.ExplodeWhenLifeFrameEnd > 0) { destroyOnEnd = true; } _destnationPixelPosition = positionInWorld; var texture = belongMagic.FlyingImage; switch (belongMagic.MoveKind) { case 15: texture = belongMagic.SuperModeImage; break; case 20: positionInWorld = Map.ToPixelPosition(belongCharacter.TilePosition); break; case 21: { var player = belongCharacter as Player; if (player != null && player.ControledCharacter != null) { player.ControledCharacter.ControledMagicSprite = this; } else { throw new Exception("Magic kind 21 internal error."); } } break; case 22: //Summon { var tilePosition = Map.ToTilePosition(positionInWorld); var finded = PathFinder.FindNonobstacleNeighborOrItself(belongCharacter, ref tilePosition); if (finded) { positionInWorld = Map.ToPixelPosition(tilePosition); } else { _isDestroyed = true; break; } if (belongCharacter.SummonedNpcsCount >= belongMagic.MaxCount) { //Reach max count belongCharacter.RemoveFirstSummonedNpc(); } var npc = NpcManager.AddNpc(belongMagic.NpcFile, (int)tilePosition.X, (int)tilePosition.Y, Utils.GetDirectionIndex(positionInWorld - belongCharacter.PositionInWorld, 8)); belongCharacter.AddSummonedNpc(npc); if (belongCharacter.IsPlayer || belongCharacter.IsFighterFriend) { npc.Relation = (int)Character.RelationType.Friend; } else { npc.Kind = (int)Character.CharacterKind.Fighter; npc.Relation = (int)Character.RelationType.Enemy; } npc.SummonedByMagicSprite = this; _summonedNpc = npc; } break; } if (belongMagic.CarryUser > 0) { belongCharacter.MovedByMagicSprite = this; } Set(positionInWorld, velocity, texture, 0); BelongMagic = belongMagic; BelongCharacter = belongCharacter; MoveDirection = moveDirection; _destroyOnEnd = destroyOnEnd; SetDirection(MoveDirection); _lastUserWorldPosition = belongCharacter.PositionInWorld; _rangeElapsedMilliseconds = belongMagic.RangeTimeInerval; if (BelongMagic.MeteorMove > 0) { _waitMilliSeconds = Globals.TheRandom.Next(1000); var dir = (BelongMagic.MeteorMoveDir > 7) ? Globals.TheRandom.Next(8) : BelongMagic.MeteorMoveDir; var path = new LinkedList <Vector2>(); path.AddFirst(positionInWorld); var tile = Map.ToTilePosition(positionInWorld, false); for (var i = 0; i <= BelongMagic.MeteorMove; i++) { tile = PathFinder.FindNeighborInDirection(tile, dir); path.AddFirst(Map.ToPixelPosition(tile, false)); } SetPath(path); PositionInWorld = path.First.Value; Velocity = belongMagic.Speed * Globals.MagicBasespeed; } return(true); }
public override void Update(GameTime gameTime) { var mouseState = Mouse.GetState(); var keyboardState = Keyboard.GetState(); var mouseScreenPosition = new Vector2(mouseState.X, mouseState.Y); var mouseWorldPosition = Globals.TheCarmera.ToWorldPosition(mouseScreenPosition); var mouseTilePosition = Map.ToTilePosition(mouseWorldPosition); _isUseMagicByKeyborad = false; _isRun = canRun(keyboardState); Globals.ClearGlobalOutEdge(); if (Kind == (int)CharacterKind.Follower) { //If player kind is changed to follower, follow the player kind npc. PartnerMoveTo(Globals.PlayerTilePosition); } else if (!GuiManager.IsMouseStateEated && CanInput) { HandleKeyboardInput(); foreach (var one in NpcManager.NpcsInView) { if (!one.IsInteractive) { continue; } var texture = one.GetCurrentTexture(); if (Collider.IsPixelCollideForNpcObj(mouseWorldPosition, one.RegionInWorld, texture)) { Globals.OutEdgeNpc = one; Globals.OutEdgeSprite = one; var edgeColor = Globals.NpcEdgeColor; if (one.IsEnemy) { edgeColor = Globals.EnemyEdgeColor; } else if (one.IsFighterFriend) { edgeColor = Globals.FriendEdgeColor; } Globals.OutEdgeColor = edgeColor; break; } } if (Globals.OutEdgeSprite == null) //not finded, try obj { foreach (var one in ObjManager.ObjsInView) { if (!one.IsInteractive) { continue; } var texture = one.GetCurrentTexture(); if (mouseTilePosition == one.TilePosition || Collider.IsPixelCollideForNpcObj(mouseWorldPosition, one.RegionInWorld, texture)) { Globals.OutEdgeObj = one; Globals.OutEdgeSprite = one; Globals.OutEdgeColor = Globals.ObjEdgeColor; Globals.OffX = one.OffX; Globals.OffY = one.OffY; break; } } } var character = this as Character; if (ControledCharacter != null) { character = ControledCharacter; } if (!IsPetrified) { if (mouseState.LeftButton == ButtonState.Pressed) { if (!IsFightDisabled && Globals.OutEdgeNpc != null && Globals.OutEdgeNpc.IsEnemy) { character.Attacking(Globals.OutEdgeNpc.TilePosition, _isRun); } else if (Globals.OutEdgeNpc != null && Globals.OutEdgeNpc != ControledCharacter && Globals.OutEdgeNpc.HasInteractScript) { if (_lastMouseState.LeftButton == ButtonState.Released) { character.InteractWith(Globals.OutEdgeNpc, _isRun); } } else if (Globals.OutEdgeObj != null && Globals.OutEdgeObj.HasInteractScript) { if (_lastMouseState.LeftButton == ButtonState.Released) { character.InteractWith(Globals.OutEdgeObj, _isRun); } } else if (_isRun) { if (CanRun()) { character.RunTo(mouseTilePosition); } else { character.WalkTo(mouseTilePosition); } } else if (keyboardState.IsKeyDown(Keys.LeftAlt) || keyboardState.IsKeyDown(Keys.RightAlt)) { character.JumpTo(mouseTilePosition); } else if (keyboardState.IsKeyDown(Keys.LeftControl) || keyboardState.IsKeyDown(Keys.RightControl)) { if (!IsFightDisabled) { character.PerformeAttack(mouseWorldPosition); } } else { character.WalkTo(mouseTilePosition); } } else { if (ControledCharacter == null) { HandleMoveKeyboardInput(); } } var rightButtonPressed = (mouseState.RightButton == ButtonState.Pressed && _lastMouseState.RightButton == ButtonState.Released); if (!IsFightDisabled && ControledCharacter == null && //Can't use magic when controling other character (rightButtonPressed || _isUseMagicByKeyborad) ) { if (CurrentMagicInUse == null) { if (!_isUseMagicByKeyborad) { GuiManager.ShowMessage("请在武功栏使用鼠标右键选择武功"); } } else if (CurrentMagicInUse.RemainColdMilliseconds > 0) { GuiManager.ShowMessage("武功尚未冷却"); } else { if (Globals.OutEdgeNpc != null) { UseMagic(CurrentMagicInUse.TheMagic, Globals.OutEdgeNpc.TilePosition, Globals.OutEdgeNpc); } else { UseMagic(CurrentMagicInUse.TheMagic, mouseTilePosition); } } } } if (keyboardState.IsKeyDown(Keys.V) && _lastKeyboardState.IsKeyUp(Keys.V) && !IsPetrified && ControledCharacter == null) { if (IsSitting()) { StandingImmediately(); } else { Sitdown(); } } } if ((IsStanding() || IsWalking()) && BodyFunctionWell) { _standingMilliseconds += (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (_standingMilliseconds >= 1000) { Life += (int)((ListRestorePercent + _extraLifeRestorePercent) * LifeMax); Thew += (int)(ThewRestorePercent * ThewMax); if (IsManaRestore) { Mana += (int)(ManaMax * ManaRestorePercent); } _standingMilliseconds = 0f; } } else { _standingMilliseconds = 0f; } if (IsSitted) { int changeManaAmount = ManaMax / 100; if (changeManaAmount == 0) { changeManaAmount = 1; } if (Mana < ManaMax && Thew > changeManaAmount) { _sittedMilliseconds += (float)gameTime.ElapsedGameTime.TotalMilliseconds; const float changeManaIntervel = 150f; if (_sittedMilliseconds >= changeManaIntervel) { _sittedMilliseconds -= changeManaIntervel; Thew -= changeManaAmount; Mana += changeManaAmount; } } else { StandingImmediately(); } } _lastMouseState = mouseState; _lastKeyboardState = keyboardState; base.Update(gameTime); }