Exemple #1
0
        public Party(string name, MobileAvatar leader)
        {
            Contract.Requires <ArgumentNullException>(leader != null);
            Contract.Requires <ArgumentNullException>(!string.IsNullOrEmpty(name));

            Name   = name;
            Leader = leader;
        }
        void ProcessMessage(ClientConnection client, PossessMobile message)
        {
            if (_world.PhysicalObjects.ContainsKey(message.InstanceId))
            {
                // reconnected
                // simply replace existing connection with the new
                // TODO: the old 'connection' should timeout or die or be killed
                var avatar = _world.PhysicalObjects[message.InstanceId] as MobileAvatar;
                if (avatar == null)
                {
                    client.LogMessage("Can only possess mobiles.");
                    return;
                }
                if (avatar.Client == client)
                {
                    client.LogMessage("You already possess " + avatar);
                    return;
                }

                if (avatar.Client != null)
                {
                    _log.Info("Mobile " + avatar.ObjectInstanceId + " has been taken over by " + client);
                    avatar.Client.LogMessage("You lost control of " + avatar);
                    avatar.Client.Avatar = null;
                }
                avatar.Client = client;
                client.Avatar = avatar;
                client.LogMessage("You are now controlling " + avatar);
            }
            else
            {
                // try to load the character
                var avatar = _world.LoadMobile(message.InstanceId);
                if (avatar == null)
                {
                    _log.Warn("Character " + message.InstanceId + " not found.");
                    //TODO: rely on world loading
                    //client.Close();
                    //return;
                    avatar = new MobileAvatar(_world);
                    avatar.ObjectInstanceId = Global.Rand.Next();
                    //TODO: don't use the players name
                    avatar.TemplateObjectName = client.AuthenticatedUsername;
                }

                avatar.Client = client;
                client.Avatar = avatar;

                // try to add the character to the world
                _world.Add(avatar);
            }
            _world.SendInitialWorldView(client);
        }
Exemple #3
0
        public static void UseSkillNow(MobileAvatar caster, UseSkill message)
        {
            Schema.EnumSkillRow esr = Global.ModelSchema.EnumSkill.FindByEnumSkillID(message.SkillId);
            if (esr == null)
            {
                caster.SendLog("Requested an invalid skill " + message.SkillId);
                return;
            }

            if (esr.EnergyCost > caster.Energy)
            {
                caster.SendLog("Not enough energy to use " + esr.EnumSkillName + ", require " + esr.EnergyCost + ".");
                return;
            }

            // TODO: make this work

            /*
             * if ( esr.EnumMobileState > caster.MobileState ) {
             *  caster.SendLog( "Not while " + caster.MobileState.Name );
             * }
             */

            MobileAvatar target;

            switch ((EnumTargetType)esr.EnumTargetTypeID)
            {
            case EnumTargetType.TargetSelf:
                target = caster;
                break;

            case EnumTargetType.TargetMobile:
                if (message.TargetPhysicalObjectIDs.Length == 0)
                {
                    caster.SendLog("No target specified, this skill may only be used on Mobiles.");
                    return;
                }
                target = (MobileAvatar)Global.World.PhysicalObjects[message.TargetPhysicalObjectIDs[0]];
                if (target == null)
                {
                    caster.SendLog("Target " + message.TargetPhysicalObjectIDs[0] + " not found.");
                    return;
                }
                if ((caster.Position - target.Position).Length > esr.Range)
                {
                    // target is out of range
                    caster.SendLog(target.TemplateObjectName + " is out of range");
                    return;
                }
                break;

            default:
                caster.SendLog("That skill does not work yet, contact admin.");
                Log.Error("Unhandled target type " + esr.EnumTargetTypeID + " for skill " + esr.EnumSkillID);
                return;
            }

            if (TargetSkill(caster, target, esr))
            {
                // successful casting affects affinity with the elements
                caster.AffinityAir   += esr.AirAffinity / 1000f;
                caster.AffinityEarth += esr.EarthAffinity / 1000f;
                caster.AffinityFire  += esr.FireAffinity / 1000f;
                caster.AffinityLife  += esr.LifeAffinity / 1000f;
                caster.AffinityWater += esr.WaterAffinity / 1000f;
            }

            // deduct energy regardless
            caster.Energy -= esr.EnergyCost;
        }
Exemple #4
0
 public static void DoKick(MobileAvatar caster, PhysicalObject target)
 {
     caster.Kick(target);
 }
Exemple #5
0
        /// <summary>
        ///  returns true on success, false on failure
        /// </summary>
        /// <param name="caster"></param>
        /// <param name="target"></param>
        /// <param name="esr"></param>
        /// <returns></returns>
        public static bool TargetSkill(MobileAvatar caster, MobileAvatar target, Schema.EnumSkillRow esr)
        {
            // test adeptness
            float  competancy = caster.GetCompetancy((EnumSkill)esr.EnumSkillID);
            double roll       = Global.Rand.NextDouble();

            if (competancy < roll * 100)
            {
                // failed
                caster.SendLog("You failed " + esr.EnumSkillName + ".");
                return(false);
            }

            switch ((EnumActivationType)esr.EnumActivationTypeID)
            {
            case EnumActivationType.AttackSpell:
                float damage = esr.EnergyCost;
                damage += esr.AirAffinity * caster.AffinityAir / target.AffinityAir;
                damage += esr.EarthAffinity * caster.AffinityEarth / target.AffinityEarth;
                damage += esr.FireAffinity * caster.AffinityFire / target.AffinityFire;
                damage += esr.LifeAffinity * caster.AffinityLife / target.AffinityLife;
                damage += esr.WaterAffinity * caster.AffinityWater / target.AffinityWater;
                caster.MagicalAttack(target, damage);
                Log.Info("Attack spell cast!");
                break;

            case EnumActivationType.Enchantment:
                break;

            case EnumActivationType.Glamour:
                break;

            case EnumActivationType.HealingSpell:
                break;

            case EnumActivationType.Skill:
                if (esr.EnumSkillID == (int)EnumSkill.Kill)
                {
                    DoKill(caster, target);
                }
                else if (esr.EnumSkillID == (int)EnumSkill.Kick)
                {
                    DoKick(caster, target);
                }
                else
                {
                    Log.Warn("Unhandled SkillID " + esr.EnumSkillID);
                }
                break;

            case EnumActivationType.Sorcery:
                break;

            default:
                caster.SendLog("That skill does not work yet, contact admin.");
                Log.Error("Unhandled activation type " + esr.EnumActivationTypeID + " for skill " + esr.EnumSkillID);
                return(false);
            }

            // if we made it this far, the skill was successful :)
            return(true);
        }
Exemple #6
0
 public void Add(MobileAvatar m)
 {
     _members.Add(m.ObjectInstanceId, m);
 }