private static void TryPlayFleeSound(ICharacter characterNpc, CharacterMobPrivateState characterNpcPrivateState)
        {
            var serverTime             = Api.Server.Game.FrameTime;
            var timeSinceLastFleeSound = serverTime - characterNpcPrivateState.LastFleeSoundTime;

            if (timeSinceLastFleeSound < FleeSoundRepeatInterval)
            {
                // already played the flee sound recently
                return;
            }

            if (timeSinceLastFleeSound < 2 * FleeSoundRepeatInterval)
            {
                // played the flee sound quite recently
                // we don't want to play it like it's a cuckoo clock (exactly every X seconds)
                // so let's apply some randomization here
                if (RandomHelper.Next(0, 5) != 0)
                {
                    return;
                }
            }

            characterNpcPrivateState.LastFleeSoundTime = serverTime;
            var protoMob = (IProtoCharacterMob)characterNpc.ProtoCharacter;

            protoMob.ServerPlaySound(characterNpc, CharacterSound.Flee);
        }
Esempio n. 2
0
        public static void SetLevel(IProtoCharacterMob protoCharacter, ICharacter character, CharacterMobPublicState publicState, CharacterMobPrivateState privateState)
        {
            if (publicState is null)
            {
                return;
            }

            int level;

            //check the zone
            int levelByZone = GetLevelByZone(character.TilePosition);

            if (levelByZone != 0)
            {
                level = levelByZone;
            }
            else
            {
                //check if there is a parent mob
                var list = character.PhysicsBody.PhysicsSpace.TestCircle(character.TilePosition.ToVector2D(), 10.0, CollisionGroups.Default).AsList()
                           .Where(t => t.PhysicsBody.AssociatedWorldObject is not null)
                           .Where(t => t.PhysicsBody.AssociatedWorldObject.ProtoWorldObject is IProtoCharacterBoss ||
                                  t.PhysicsBody.AssociatedWorldObject.ProtoWorldObject is IProtoCharacterSmallBoss).ToList();

                level = GetLevel(protoCharacter);

                if (list.Count > 0)
                {
                    var mobPublicState = list[0].PhysicsBody.AssociatedWorldObject.GetPublicState <CharacterMobPublicState>();
                    if (mobPublicState is not null && level > mobPublicState.Level)
                    {
                        level = mobPublicState.Level;
                    }
                }
            }

            publicState.Level = level;
        }