private void Begin() { _leftLeapTimes = BelongMagic.LeapTimes; _currentEffect = MagicManager.GetEffectAmount(BelongMagic, BelongCharacter); _currentEffect2 = MagicManager.GetEffectAmount2(BelongMagic, BelongCharacter); _currentEffectMana = BelongMagic.EffectMana; if (_leftLeapTimes > 0) { //Initilize leap _leapedCharacters = new List <Character>(); _canLeap = true; } //Start play FlyingImage ResetPlay(); if (Velocity > 0 && MoveDirection != Vector2.Zero)//Move 30 { var second = 30f / Velocity; MoveToNoNormalizeDirection(MoveDirection, second); } else { // can't put fixed position magic sprite in obstacle if (CheckDestroyForObstacleInMap()) { _isDestroyed = true; } } }
private void LoadMap(byte[] buf) { //Clear ingnored traps list _ingnoredTrapsIndex.Clear(); Free(); //Clear asf cache, because normaly npcs objs will be cleared after map load. Utils.ClearTextureCache(); //Destory magic sprite in current map MagicManager.Renew(); var offset = 0; try { if (!LoadHead(buf, ref offset)) { return; } LoadMpc(buf, ref offset); LoadMapTiles(buf, ref offset); } catch (Exception e) { Log.LogMessageToFile("Map file is corrupted" + ": " + e); } IsOk = true; }
private void UseExplodeMagic() { if (BelongMagic.ExplodeMagicFile != null) { MagicManager.UseMagic(BelongCharacter, BelongMagic.ExplodeMagicFile, PositionInWorld, RealMoveDirection == Vector2.Zero ? PositionInWorld + (PositionInWorld - BelongCharacter.PositionInWorld) : PositionInWorld + RealMoveDirection); } }
public override bool HasObstacle(Vector2 tilePosition) { if (Kind == (int)CharacterKind.Flyer) { return(false); } return(NpcManager.IsObstacle(tilePosition) || ObjManager.IsObstacle(tilePosition) || MagicManager.IsObstacle(tilePosition) || Globals.ThePlayer.TilePosition == tilePosition); }
protected override void OnAttacking(Vector2 attackDestinationPixelPosition) { if (State == (int)CharacterState.Attack2 && XiuLianMagic != null && XiuLianMagic.TheMagic != null && XiuLianMagic.TheMagic.AttackFile != null) { MagicManager.UseMagic(this, XiuLianMagic.TheMagic.AttackFile, PositionInWorld, attackDestinationPixelPosition); } }
private void UseMagic(Magic magic) { if (magic == null) { return; } MagicManager.UseMagic(BelongCharacter, magic, PositionInWorld, RealMoveDirection == Vector2.Zero ? PositionInWorld + (PositionInWorld - BelongCharacter.PositionInWorld) : PositionInWorld + RealMoveDirection); }
private void UpdatePlaying(GameTime gameTime) { if (Globals.IsInSuperMagicMode) { Globals.SuperModeMagicSprite.Update(gameTime); if (Globals.SuperModeMagicSprite.IsDestroyed) { Globals.IsInSuperMagicMode = false; Globals.SuperModeMagicSprite = null; } return;//Just update super magic } else if (TimeStoperMagicSprite != null) { TimeStoperMagicSprite.BelongCharacter.Update(gameTime); TimeStoperMagicSprite.Update(gameTime); MapBase.Instance.Update(gameTime); MagicManager.UpdateMagicSpritesInView(); NpcManager.UpdateNpcsInView(); ObjManager.UpdateObjsInView(); return; } //Player Globals.ThePlayer.Update(gameTime); //Magic list MagicManager.Update(gameTime); MagicManager.UpdateMagicSpritesInView(); //Npc list NpcManager.Update(gameTime); NpcManager.UpdateNpcsInView(); //Obj list ObjManager.Update(gameTime); ObjManager.UpdateObjsInView(); //Map MapBase.Instance.Update(gameTime); //Weather WeatherManager.Update(gameTime); }
public override void Update(GameTime gameTime) { if (IsDestroyed) { return; } if (_waitMilliSeconds > 0) { _waitMilliSeconds -= (float)gameTime.ElapsedGameTime.TotalMilliseconds; return; } if (_parasitiferCharacter != null) { PositionInWorld = _parasitiferCharacter.PositionInWorld; if (_parasitiferCharacter.IsDeathInvoked) { _parasitiferCharacter = null; _isDestroyed = true; } else { _parasticTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (_parasticTime >= BelongMagic.ParasiticInterval) { _parasticTime -= BelongMagic.ParasiticInterval; UseMagic(BelongMagic.ParasiticMagic); CharacterHited(_parasitiferCharacter, MagicManager.GetEffectAmount(BelongMagic, BelongCharacter), MagicManager.GetEffectAmount2(BelongMagic, BelongCharacter), BelongMagic.EffectMana, false); if (BelongMagic.ParasiticMaxEffect > 0 && _totalParasticEffect >= BelongMagic.ParasiticMaxEffect) { _parasitiferCharacter = null; _isDestroyed = true; } } } } if (_paths != null) { if (_paths.Count > 1) { var beginPosition = _paths.First.Value; var endPosition = _paths.First.Next.Value; var distance = Vector2.Distance(beginPosition, endPosition); MoveTo(endPosition - beginPosition, (float)gameTime.ElapsedGameTime.TotalSeconds); if (MovedDistance >= distance) { _paths.RemoveFirst(); MovedDistance = 0; PositionInWorld = endPosition; if (_paths.Count < 2) { if (_destroyOnEnd || BelongMagic.MeteorMove > 0) { Destroy(); } CheckCharacterHited(); } } } } else { if (!IsInDestroy) { if (BelongMagic.FollowMouse > 0) { var mouseState = Mouse.GetState(); var mouseScreenPosition = new Vector2(mouseState.X, mouseState.Y); var mouseWorldPosition = Globals.TheCarmera.ToWorldPosition(mouseScreenPosition); var direction = mouseWorldPosition - PositionInWorld; MoveDirection = direction.Length() > 25 ? direction : Vector2.Zero; } else if (BelongMagic.RandomMoveDegree > 0) { while (MoveDirection == Vector2.Zero) { MoveDirection = new Vector2((float)Globals.TheRandom.Next(-100, 100) / 100.0f, (float)Globals.TheRandom.Next(-100, 100) / 100.0f); } var perpendicular1 = new Vector2(MoveDirection.Y, -MoveDirection.X); var perpendicular2 = new Vector2(-MoveDirection.Y, MoveDirection.X); var random = (Globals.TheRandom.Next(2) == 0 ? perpendicular1 : perpendicular2) * Globals.TheRandom.Next(BelongMagic.RandomMoveDegree); MoveDirection += random; } if (BelongMagic.MoveImitateUser > 0) { PositionInWorld += (BelongCharacter.PositionInWorld - _lastUserWorldPosition); _lastUserWorldPosition = BelongCharacter.PositionInWorld; } if (BelongMagic.CircleMoveColockwise > 0 || BelongMagic.CircleMoveAnticlockwise > 0) { var dir = PositionInWorld - BelongCharacter.PositionInWorld; if (dir != Vector2.Zero) { dir.Normalize(); dir = BelongMagic.CircleMoveColockwise > 0 ? new Vector2(-dir.Y, dir.X) : new Vector2(dir.Y, -dir.X); _circleMoveDir = dir; } } if (_isInMoveBack) { //Move back to magic user. var dir = BelongCharacter.PositionInWorld - PositionInWorld; MoveDirection = dir; if (dir.Length() < 20) { _isInMoveBack = false; _isDestroyed = true; } } } if (BelongMagic.MoveKind == 16) { if (MovedDistance > 200f) //First move 200, than find target { if (BelongCharacter.IsPlayer || BelongCharacter.IsFriend) { if (_closedCharecter == null || _closedCharecter.IsDeath) { _closedCharecter = NpcManager.GetClosestEnemyTypeCharacter(PositionInWorld); } } else { _closedCharecter = Globals.ThePlayer; } if (_closedCharecter != null) { MoveDirection = _closedCharecter.PositionInWorld - PositionInWorld; } } MoveToNoNormalizeDirection(RealMoveDirection, (float)gameTime.ElapsedGameTime.TotalSeconds, MagicManager.GetSpeedRatio(RealMoveDirection)); } else if (_isInDestroy) { //Stop moving when in destroy. } else { MoveToNoNormalizeDirection(RealMoveDirection, (float)gameTime.ElapsedGameTime.TotalSeconds); } } if (BelongMagic.MoveKind == 13 || BelongMagic.MoveKind == 23) { PositionInWorld = BelongCharacter.PositionInWorld; } if (!_isInDestroy) { if (BelongMagic.RangeEffect > 0) { _rangeElapsedMilliseconds += (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (_rangeElapsedMilliseconds >= BelongMagic.RangeTimeInerval) { _rangeElapsedMilliseconds -= BelongMagic.RangeTimeInerval; if (BelongMagic.RangeAddLife > 0 || BelongMagic.RangeAddMana > 0 || BelongMagic.RangeAddThew > 0 || BelongMagic.RangeSpeedUp > 0) { foreach (var target in NpcManager.FindFriendInTileDistance(BelongCharacter, TilePosition, BelongMagic.RangeRadius)) { if (BelongMagic.RangeAddLife > 0) { target.AddLife(BelongMagic.RangeAddLife); } if (BelongMagic.RangeAddMana > 0) { target.AddMana(BelongMagic.RangeAddMana); } if (BelongMagic.RangeAddThew > 0) { target.AddThew(BelongMagic.RangeAddThew); } if (BelongMagic.RangeSpeedUp > 0 && target.SppedUpByMagicSprite == null) { target.SppedUpByMagicSprite = this; } } } if (BelongMagic.RangeFreeze > 0 || BelongMagic.RangePoison > 0 || BelongMagic.RangePetrify > 0 || BelongMagic.RangeDamage > 0) { foreach (var target in NpcManager.FindEnemiesInTileDistance(BelongCharacter, TilePosition, BelongMagic.RangeRadius)) { if (BelongMagic.RangeFreeze > 0) { target.SetFrozenSeconds(BelongMagic.RangeFreeze / 1000.0f, BelongMagic.NoSpecialKindEffect == 0); } if (BelongMagic.RangePoison > 0) { target.SetPoisonSeconds(BelongMagic.RangePoison / 1000.0f, BelongMagic.NoSpecialKindEffect == 0); } if (BelongMagic.RangePetrify > 0) { target.SetPetrifySeconds(BelongMagic.RangePetrify / 1000.0f, BelongMagic.NoSpecialKindEffect == 0); } if (BelongMagic.RangeDamage > 0) { CharacterHited(target, BelongMagic.RangeDamage, BelongMagic.Effect2, 0); AddDestroySprite(MagicManager.EffectSprites, target.PositionInWorld, BelongMagic.VanishImage, BelongMagic.VanishSound); } } } } } if (BelongMagic.FlyMagic != null) { _flyMagicElapsedMilliSeconds += (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (_flyMagicElapsedMilliSeconds >= BelongMagic.FlyInterval) { _flyMagicElapsedMilliSeconds -= BelongMagic.FlyInterval; var dir = RealMoveDirection == Vector2.Zero ? PositionInWorld - BelongCharacter.PositionInWorld : RealMoveDirection; MagicManager.UseMagic(BelongCharacter, BelongMagic.FlyMagic, PositionInWorld, PositionInWorld + dir); } } } if (IsInDestroy) { if (BelongMagic.MoveKind == 15) { var end = false; foreach (var sprite in _superModeDestroySprites) { sprite.Update(gameTime); if (!sprite.IsInPlaying) { end = true; break; } } if (end) { _isDestroyed = true; } } else { if (!IsInPlaying) { _isDestroyed = true; } } } else if (_paths != null) { //do nothing } else if (BelongMagic.MoveKind == 15) { if (!IsInPlaying) { Destroy(); } } else if (BelongMagic.MoveKind == 22) //Summon { if (_summonElapsedMilliseconds < BelongMagic.KeepMilliseconds) { _summonElapsedMilliseconds += (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (!IsInPlaying) { Texture = Asf.Empty; } } else { Destroy(); } } else { var checkHit = true; switch (BelongMagic.MoveKind) { case 13: case 20: //transport case 21: //Controling others case 22: case 23: //Time stoper checkHit = false; break; default: CheckCharacterHited(); break; } if (checkHit && CheckDestroyForObstacleInMap()) { Destroy(); } else if (!IsInPlaying) { if (BelongMagic.MoveBack > 0) { if (Velocity == 0.0f) { Velocity = Globals.MagicBasespeed * BelongMagic.Speed; } _isInMoveBack = true; } else if (_destroyOnEnd) { Destroy(); } else { _isDestroyed = true; } } } base.Update(gameTime); }
private void CharacterHited(Character character, int damage, int damage2, int damageMana, bool addMagicHitedExp = true) { var isInDeath = character.IsDeathInvoked; character.LastAttackerMagicSprite = this; //Hit ratio var targetEvade = character.Evade; var belongCharacterEvade = BelongCharacter.Evade; const float maxOffset = 100f; const float baseHitRatio = 0.05f; const float belowRatio = 0.5f; const float upRatio = 0.45f; var hitRatio = baseHitRatio; if (targetEvade >= belongCharacterEvade) { hitRatio += ((float)belongCharacterEvade / (float)targetEvade) * belowRatio; } else { var upOffsetRatio = ((float)belongCharacterEvade - targetEvade) / maxOffset; if (upOffsetRatio > 1f) { upOffsetRatio = 1f; } hitRatio += belowRatio + upOffsetRatio * upRatio; } if (_parasitiferCharacter != null || Globals.TheRandom.Next(101) <= (int)(hitRatio * 100f)) { var effect2 = damage2 - character.Defend2; var effect = (damage - character.Defend); foreach (var magicSprite in character.MagicSpritesInEffect) { var magic = magicSprite.BelongMagic; switch (magic.MoveKind) { case 13: if (magic.SpecialKind == 3) { //Target character have protecter var damageReduce = MagicManager.GetEffectAmount(magic, character); var damageReduce2 = MagicManager.GetEffectAmount2(magic, character); effect2 -= damageReduce2; effect -= damageReduce; } break; } } if (effect2 > 0) { effect += effect2; } if (effect > character.Life) { //Effect amount should less than or equal target character current life amount. effect = character.Life; } character.DecreaseLifeAddHurt(effect < MinimalDamage ? MinimalDamage : effect); character.DecreaseMana(damageMana); //Restore if (BelongMagic.RestoreProbability > 0 && Globals.TheRandom.Next(0, 100) < BelongMagic.RestoreProbability) { var restoreAmount = (effect * BelongMagic.RestorePercent) / 100; switch ((Magic.RestorePropertyType)BelongMagic.RestoreType) { case Magic.RestorePropertyType.Life: BelongCharacter.AddLife(restoreAmount); break; case Magic.RestorePropertyType.Mana: BelongCharacter.AddMana(restoreAmount); break; case Magic.RestorePropertyType.Thew: BelongCharacter.AddThew(restoreAmount); break; default: throw new ArgumentOutOfRangeException(); } } } if (_parasitiferCharacter != null) { _totalParasticEffect += damage; } if (character.MagicToUseWhenBeAttacked != null) { Vector2 destination; Character target = null; var dirType = (Character.BeAttackedUseMagicDirection)character.MagicDirectionWhenBeAttacked; switch (dirType) { case Character.BeAttackedUseMagicDirection.Attacker: destination = BelongCharacter.PositionInWorld; target = BelongCharacter; break; case Character.BeAttackedUseMagicDirection.MagicSpriteOppDirection: destination = RealMoveDirection == Vector2.Zero ? (character.PositionInWorld + Utils.GetDirection8(character.CurrentDirection)) : (character.PositionInWorld - RealMoveDirection); break; case Character.BeAttackedUseMagicDirection.CurrentNpcDirection: destination = character.PositionInWorld + Utils.GetDirection8(character.CurrentDirection); break; default: destination = BelongCharacter.PositionInWorld; break; } MagicManager.UseMagic(character, character.MagicToUseWhenBeAttacked, character.PositionInWorld, destination, target); } { Player player = null; MagicListManager.MagicItemInfo info = null; if (BelongCharacter.IsPlayer) { player = BelongCharacter as Player; info = BelongMagic.ItemInfo; } else if (BelongCharacter.ControledMagicSprite != null) { player = BelongCharacter.ControledMagicSprite.BelongCharacter as Player; if (player != null) { info = player.CurrentMagicInUse; } } else if (BelongCharacter.SummonedByMagicSprite != null && BelongCharacter.SummonedByMagicSprite.BelongCharacter.IsPlayer) { //Summoned by player, add player's exp player = BelongCharacter.SummonedByMagicSprite.BelongCharacter as Player; if (player != null) { info = player.CurrentMagicInUse; } } if (addMagicHitedExp && player != null && info != null) { var amount = Utils.GetMagicExp(character.Level); player.AddMagicExp(info, amount); } } //Exp if (BelongCharacter.IsPlayer || BelongCharacter.IsFighterFriend) { character.NotifyEnemyAndAllNeighbor(BelongCharacter); var isSummonedByPlayerorPartner = (BelongCharacter.SummonedByMagicSprite != null && (BelongCharacter.SummonedByMagicSprite.BelongCharacter.IsPlayer || BelongCharacter.SummonedByMagicSprite.BelongCharacter.IsPartner)); var isControledByPlayer = (BelongCharacter.ControledMagicSprite != null && BelongCharacter.ControledMagicSprite.BelongCharacter.IsPlayer); //Hited character death if (!isInDeath && //Alive before hited character.IsInDeathing && //Death after hited (BelongCharacter.IsPlayer || BelongCharacter.IsPartner || isSummonedByPlayerorPartner || isControledByPlayer)) { var player = Globals.ThePlayer; var exp = Utils.GetCharacterDeathExp(Globals.ThePlayer, character); player.AddExp(exp, true); } } }
private void CharacterHited(Character character) { if (character == null) { return; } var destroy = true; if (BelongMagic.Bounce > 0) { var direction = (RealMoveDirection == Vector2.Zero) ? (character.PositionInWorld - PositionInWorld) : RealMoveDirection; if (direction != Vector2.Zero) { var velocity = BelongMagic.Bounce; if (character.BouncedVelocity > 0) { direction.Normalize(); direction = (character.BouncedDirection * character.BouncedVelocity + direction * BelongMagic.Bounce); velocity = (int)direction.Length(); } character.BouncedDirection = direction; character.BouncedVelocity = velocity; character.StandingImmediately(); } } if (BelongMagic.Ball > 0) { destroy = false; MoveDirection = PathFinder.BouncingAtPoint(RealMoveDirection, PositionInWorld, character.PositionInWorld); //Hitted once, Move magic sprite to neighber tile TilePosition = PathFinder.FindNeighborInDirection(TilePosition, RealMoveDirection); PositionInWorld -= (RealMoveDirection == Vector2.Zero ? Vector2.Zero : Vector2.Normalize(RealMoveDirection)); AddDestroySprite(MagicManager.EffectSprites, PositionInWorld, BelongMagic.VanishImage, BelongMagic.VanishSound); } if (BelongMagic.Sticky > 0) { destroy = false; character.StandingImmediately(); character.MovedByMagicSprite = this; _stickedCharacter = character; if (BelongMagic.MoveBack > 0 && _isInMoveBack == false) { _isInMoveBack = true; } } if (BelongMagic.Parasitic > 0) { _parasitiferCharacter = character; destroy = true; } //Apply magic special effect switch (BelongMagic.SpecialKind) { case 1: character.SetFrozenSeconds(BelongMagic.EffectLevel + 1, BelongMagic.NoSpecialKindEffect == 0); break; case 2: character.SetPoisonSeconds(BelongMagic.EffectLevel + 1, BelongMagic.NoSpecialKindEffect == 0); break; case 3: character.SetPetrifySeconds(BelongMagic.EffectLevel + 1, BelongMagic.NoSpecialKindEffect == 0); break; } //Additional attack effect added to magic when player equip special equipment switch (BelongMagic.AdditionalEffect) { case Magic.AddonEffect.Frozen: if (!character.IsFrozened) { character.SetFrozenSeconds(BelongCharacter.Level / 10 + 1, BelongMagic.NoSpecialKindEffect == 0); } break; case Magic.AddonEffect.Poision: if (!character.IsPoisoned) { character.SetPoisonSeconds(BelongCharacter.Level / 10 + 1, BelongMagic.NoSpecialKindEffect == 0); } break; case Magic.AddonEffect.Petrified: if (!character.IsPetrified) { character.SetPetrifySeconds(BelongCharacter.Level / 10 + 1, BelongMagic.NoSpecialKindEffect == 0); } break; } var amount = _canLeap ? _currentEffect : MagicManager.GetEffectAmount(BelongMagic, BelongCharacter); var amount2 = _canLeap ? _currentEffect2 : MagicManager.GetEffectAmount2(BelongMagic, BelongCharacter); var amountMana = _canLeap ? _currentEffectMana : BelongMagic.EffectMana; CharacterHited(character, amount, amount2, amountMana); if (_canLeap) { LeapToNextTarget(character); } else if (BelongMagic.PassThrough > 0) { if (BelongMagic.PassThroughWithDestroyEffect > 0) { AddDestroySprite(MagicManager.EffectSprites, PositionInWorld, BelongMagic.VanishImage, BelongMagic.VanishSound); } if (Velocity > 0 && RealMoveDirection != Vector2.Zero) { //Hit once, move magic sprite to neighber tile TilePosition = PathFinder.FindNeighborInDirection(TilePosition, RealMoveDirection); } } else if (destroy) { Destroy(); } }
private void CharacterHited(Character character, int damage) { //Hit ratio var targetEvade = character.Evade; var belongCharacterEvade = BelongCharacter.Evade; const float maxOffset = 100f; const float baseHitRatio = 0.05f; const float belowRatio = 0.5f; const float upRatio = 0.45f; var hitRatio = baseHitRatio; if (targetEvade >= belongCharacterEvade) { hitRatio += ((float)belongCharacterEvade / (float)targetEvade) * belowRatio; } else { var upOffsetRatio = ((float)belongCharacterEvade - targetEvade) / maxOffset; if (upOffsetRatio > 1f) { upOffsetRatio = 1f; } hitRatio += belowRatio + upOffsetRatio * upRatio; } if (Globals.TheRandom.Next(101) <= (int)(hitRatio * 100f)) { var effect = damage - character.Defend; foreach (var magicSprite in character.MagicSpritesInEffect) { var magic = magicSprite.BelongMagic; switch (magic.MoveKind) { case 13: if (magic.SpecialKind == 3) { //Target character have protecter var damageReduce = MagicManager.GetEffectAmount(magic, character); effect -= damageReduce; } break; } } if (effect > character.Life) { //Effect amount should less than or equal target character current life amount. effect = character.Life; } character.DecreaseLifeAddHurt(effect < MinimalDamage ? MinimalDamage : effect); //Restore if (BelongMagic.RestoreProbability > 0 && Globals.TheRandom.Next(0, 100) < BelongMagic.RestoreProbability) { var restoreAmount = (effect * BelongMagic.RestorePercent) / 100; switch ((Magic.RestorePropertyType)BelongMagic.RestoreType) { case Magic.RestorePropertyType.Life: BelongCharacter.AddLife(restoreAmount); break; case Magic.RestorePropertyType.Mana: BelongCharacter.AddMana(restoreAmount); break; case Magic.RestorePropertyType.Thew: BelongCharacter.AddThew(restoreAmount); break; default: throw new ArgumentOutOfRangeException(); } } } { Player player = null; MagicListManager.MagicItemInfo info = null; if (BelongCharacter.IsPlayer) { player = BelongCharacter as Player; info = BelongMagic.ItemInfo; } else if (BelongCharacter.ControledMagicSprite != null) { player = BelongCharacter.ControledMagicSprite.BelongCharacter as Player; if (player != null) { info = player.CurrentMagicInUse; } } else if (BelongCharacter.SummonedByMagicSprite != null && BelongCharacter.SummonedByMagicSprite.BelongCharacter.IsPlayer) { //Summoned by player, add player's exp player = BelongCharacter.SummonedByMagicSprite.BelongCharacter as Player; if (player != null) { info = player.CurrentMagicInUse; } } if (player != null && info != null) { var amount = Utils.GetMagicExp(character.Level); player.AddMagicExp(info, amount); } } }
public override bool HasObstacle(Vector2 tilePosition) { return(NpcManager.IsObstacle(tilePosition) || ObjManager.IsObstacle(tilePosition) || MagicManager.IsObstacle(tilePosition)); }