Exemple #1
0
        private static bool MakeFleeAttempt(CharacterInstance ch, RoomTemplate wasIn)
        {
            var door = db.number_door();
            var exit = wasIn.GetExit(door);

            if (exit?.GetDestination() == null || exit.Flags.IsSet(ExitFlags.NoFlee) || exit.Flags.IsSet(ExitFlags.Closed) || !ch.IsAffected(AffectedByTypes.PassDoor) || (ch.IsNpc() && exit.GetDestination().Flags.IsSet(RoomFlags.NoMob)))
            {
                return(false);
            }

            var sneak = RepositoryManager.Instance.GetEntity <SkillData>("sneak");

            if (sneak == null)
            {
                return(false);
            }

            ch.StripAffects((int)sneak.ID);
            ch.AffectedBy.RemoveBit((int)AffectedByTypes.Sneak);

            if (ch.CurrentMount?.CurrentFighting != null)
            {
                ch.CurrentMount.StopFighting(true);
            }
            Move.move_char(ch, exit, 0);

            var nowIn = ch.CurrentRoom;

            if (nowIn == wasIn)
            {
                return(false);
            }

            ch.CurrentRoom = wasIn;
            comm.act(ATTypes.AT_FLEE, "$n flees head over heels!", ch, null, null, ToTypes.Room);

            ch.CurrentRoom = nowIn;
            comm.act(ATTypes.AT_FLEE, "$n glances around for signs of pursuit.", ch, null, null, ToTypes.Room);

            if (!ch.IsNpc())
            {
                var wf  = ch.GetMyTarget();
                var pch = (PlayerInstance)ch;

                comm.act(ATTypes.AT_FLEE, "You flee head over heels from combat!", pch, null, null, ToTypes.Character);

                if (pch.Level < LevelConstants.AvatarLevel)
                {
                    LoseExperience(pch);
                }

                if (wf != null)
                {
                    if (pch.PlayerData.CurrentDeity != null)
                    {
                        var ratio = 1.GetNumberThatIsBetween(wf.Level / pch.Level, LevelConstants.MaxLevel);
                        if (wf.CurrentRace == pch.PlayerData.CurrentDeity.NPCRace)
                        {
                            pch.AdjustFavor(DeityFieldTypes.FleeNPCRace, ratio);
                        }
                        else if (wf.CurrentRace == pch.PlayerData.CurrentDeity.NPCFoe)
                        {
                            pch.AdjustFavor(DeityFieldTypes.FleeNPCFoe, ratio);
                        }
                        else
                        {
                            pch.AdjustFavor(DeityFieldTypes.Flee, ratio);
                        }
                    }
                }
            }

            ch.StopFighting(true);
            return(true);
        }