Exemplo n.º 1
0
        public static void ProcessUseSkill(ClientConnection client, UseSkill message)
        {
            var avatar = client.Avatar as MobileAvatar;
            if (avatar == null)
            {
                client.LogMessage("Requested a skill, but doesn't have an avatar.");
                return;
            }
            Schema.EnumSkillRow esr = Global.ModelSchema.EnumSkill.FindByEnumSkillID(message.SkillId);
            if (esr == null)
            {
                client.LogMessage("Requested an invalid skill " + message.SkillId);
                return;
            }

            // If already performing a skill invocation, just queue the request for later.
            if (avatar.ActivatingSkill != null)
            {
                avatar.SkillQueue.Enqueue(message);
                return;
            }

            if (esr.LeadTime <= 0)
            {
                // process it now
                UseSkillNow(avatar, message);
            }
            else
            {
                // process it later, after lead-time has elapsed
                avatar.ActivatingSkill = message;
                avatar.ActivatingSkillTimestamp = Global.Now;
                avatar.ActivatingSkillLeadTime = TimeSpan.FromSeconds(esr.LeadTime);
            }
        }
        public static void ProcessUseSkill(this World world, ClientConnection client, UseSkill message)
        {
            var source = client.Avatar as CombatantModel;
            if (source == null)
            {
                client.LogMessage("Requested a skill without an avatar.");
                return;
            }

            Schema.EnumSkillRow esr = Global.Schema.EnumSkill.FindByEnumSkillID((int)message.Skill);
            if (esr == null)
            {
                client.LogMessage("Requested an invalid skill " + message.Skill);
                return;
            }

            EntityModel target;
            switch ((EnumTargetType)esr.EnumTargetTypeID)
            {
                case EnumTargetType.TargetSelf:
                    target = source;
                    break;
                case EnumTargetType.TargetMobile:
                    if (message.TargetPhysicalObjectIDs.Length == 0)
                    {
                        world.LogMessage(source, "No target specified, this skill may only be used on Mobiles.");
                        return;
                    }
                    target = world.History.Head.Entities.ValueOrDefault(message.TargetPhysicalObjectIDs[0]);
                    if (target == null)
                    {
                        world.LogMessage(source, "Target " + message.TargetPhysicalObjectIDs[0] + " not found.");
                        return;
                    }
                    break;
                default:
                    world.LogMessage(source, "That skill has an unsupported target type " + esr.EnumTargetTypeID);
                    Log.Error("Unhandled target type " + esr.EnumTargetTypeID + " for skill " + esr.EnumSkillID + " " + esr.EnumSkillName);
                    return;
            }


            if (source.ActivatingSkill != EnumSkill.None)         // queue the request for later.
                world.Apply(new EntityUpdateEvent(
                    source.EnqueueSkill(message.Skill, target),
                    "Enqueuing Skill " + message.Skill));
            else if (esr.LeadTime <= 0)                 // process it now
                world.UseSkillNow(source, esr, target);
            else                                        // process it later, after lead-time has elapsed
                world.Apply(new EntityUpdateEvent(
                    source.StartSkill(message.Skill, target, Global.Now, TimeSpan.FromSeconds(esr.LeadTime)),
                    "Activating Skill " + message.Skill));
        }
Exemplo n.º 3
0
        public static void ProcessCancelSkill(ClientConnection client, CancelSkill message)
        {
            var avatar = client.Avatar as MobileAvatar;
            if (avatar == null)
            {
                client.LogMessage("Canceled a skill invocation, but don't have an avatar.");
                return;
            }

            // If already performing invocation, just cancel it
            bool found = false;
            if (avatar.ActivatingSkill != null && avatar.ActivatingSkill.InvokationId == message.InvokationId)
            {
                avatar.ActivatingSkill = null;
                found = true;
            }
            else
            {
                // search for it in queued skill invocations
                // just generate a new queue with the invocation missing
                var newQueue = new Queue<UseSkill>();
                foreach (UseSkill m in avatar.SkillQueue)
                {
                    if (m.InvokationId == message.InvokationId)
                    {
                        // don't add it
                        found = true;
                    }
                    else
                        newQueue.Enqueue(m);
                }
                avatar.SkillQueue = newQueue;
            }
            if (found)
                client.LogMessage("Successfully canceled invocation " + message.InvokationId);
            else
                client.LogMessage("Failed to cancel invocation " + message.InvokationId);
        }
        public static void ProcessCancelSkill(this World world, ClientConnection client, CancelSkill message)
        {
            var avatar = client.Avatar as CombatantModel;
            if (avatar == null)
            {
                client.LogMessage("Canceled a skill invocation, but don't have an avatar.");
                return;
            }

            // If already performing invocation, just cancel it
            bool found = false;
            if (avatar.ActivatingSkill != EnumSkill.None)
            // TODO:
            //&& avatar.ActivatingSkill.InvokationId == message.InvokationId)
            {
                world.Apply(new EntityUpdateEvent(avatar.StartSkill(EnumSkill.None, null, Global.Now, TimeSpan.FromSeconds(0)),
                    "Started using skill"));
                found = true;
            }
            else
            {
                // TODO: search for it in queued skill invocations
                // just generate a new queue with the invocation missing
                /*
                var newQueue = new Queue<UseSkill>();
                foreach (UseSkill m in avatar.SkillQueue)
                {
                    if (m.InvokationId == message.InvokationId)
                    {
                        // don't add it
                        found = true;
                    }
                    else
                        newQueue.Enqueue(m);
                }
                avatar.SkillQueue = newQueue;
                 */
                avatar.EmptyQueue();
            }
            if (found)
                client.LogMessage("Successfully canceled invocation " + message.InvokationId);
            else
                client.LogMessage("Failed to cancel invocation " + message.InvokationId);
        }
Exemplo n.º 5
0
 void ProcessMessage(ClientConnection client, InviteToParty message)
 {
     if (World.Party[client.AuthenticatedUsername] == null)
     {
         client.LogMessage("You are not the leader of a party");
         return;
     }
     var target = World.Users[message.User];
     if (target == null)
         client.LogMessage("Invalid target");
     else
     {
         World.InvitedToParty[target.AuthenticatedUsername]
             .Add(client.AuthenticatedUsername, Global.Now);
         // TODO: probably want a graphical thing or something for invites
         target.LogMessage("You have been invited to party '" + client.AuthenticatedUsername + "'");
     }
 }
Exemplo n.º 6
0
        void ProcessMessage(ClientConnection client, ProduceEntity p)
        {
            var factory = World.History.Head.Entities.ValueOrDefault(p.FactoryId);
            if (factory == null)
            {
                client.LogMessage("Could not find factory " + p.FactoryId);
                return;
            }

            World.Apply(new ProductionStartedEvent(
                factory.Id, p.Id,
                client.AuthenticatedUsername + " producing " + p.Name + " from " + factory));
        }
Exemplo n.º 7
0
        void ProcessMessage(ClientConnection client, JoinParty message)
        {
            Dictionary<string, DateTime> invitation;
            if (!World.InvitedToParty.TryGetValue(client.AuthenticatedUsername, out invitation))
            {
                client.LogMessage("You are not currently invited to join a party");
                return;
            }

            // make sure they are trying to join the party they were invited to
            if (!invitation.ContainsKey(message.Leader))
            {
                client.LogMessage("You are not currently invited to join " + message.Leader);
                return;
            }

            HashSet<string> party;
            if (!World.Party.TryGetValue(message.Leader, out party))
            {
                client.LogMessage("That party does not exist anymore");
                return;
            }

            World.SendPartyTalk(client, message.Leader, client.Avatar.Name + " has joined your ");
            party.Add(client.AuthenticatedUsername);
            client.LogMessage("You are now in party '" + message.Leader + "'.");

            //World.InvitedToParty.Remove(message.Leader);
        }
Exemplo n.º 8
0
 void ProcessMessage(ClientConnection client, LeaveParty message)
 {
     World.LeaveParty(client, client.AuthenticatedUsername);
     client.LogMessage("You have left party");
 }
Exemplo n.º 9
0
        void ProcessMessage(ClientConnection client, TransferPartyLeadership message)
        {
            var avatar = client.Avatar;
            ClientConnection target;
            if (!World.Users.TryGetValue(message.Leader, out target))
            {
                client.LogMessage("Invalid target");
                return;
            }

            if (client.AuthenticatedUsername == message.Leader)
            {
                client.LogMessage("You are already the leader");
                return;
            }

            HashSet<string> party;
            if (!World.Party.TryGetValue(client.AuthenticatedUsername, out party))
            {
                client.LogMessage("You are not the leader of a party");
                return;
            }

            // TODO: use character names instead of username??
            if (!party.Contains(message.Leader))
            {
                client.LogMessage(message.Leader + " is not in your party");
                return;
            }

            World.TransferLeadership(client.AuthenticatedUsername, message.Leader);
            World.SendPartyTalk(client, "Party leadership has been transferred to " + message.Leader);
        }
Exemplo n.º 10
0
        void ProcessMessage(ClientConnection client, MyPosition message)
        {
            var avatar = client.Avatar;
            if (avatar == null)
            {
                client.LogMessage("Position message sent, but have no avatar.");
                return;
            }

            if (message.Position != avatar.Position)
                World.Apply(new EntityUpdateEvent(
                    avatar.Move(message.MobileState, message.Position, message.Rotation, Global.Now),
                    "Player movement"));
        }
Exemplo n.º 11
0
        void ProcessMessage(ClientConnection client, PossessMobile message)
        {
            var avatar = World.History.Head.Entities.ValueOrDefault(message.InstanceId);
            if (avatar != null)
            {
                // reconnected, replace existing connection with the new
                ClientConnection possessedBy;
                if (World.Possession.TryGetValue(avatar.Id, out possessedBy))
                {
                    if (possessedBy == client)
                    {
                        client.LogMessage("You already possess " + avatar);
                        return;
                    }
                    else
                    {
                        _log.Info("Mobile " + avatar + " has been taken over by " + client);
                        possessedBy.LogMessage("You lost control of " + avatar);
                        possessedBy.Avatar = null;
                    }
                }
                if (client.Avatar != null && client.Avatar.Id != avatar.Id)
                {
                    // TODO: omg releasing this sends a combatant which crashes
                    // release control of previous avatar
                    //World.Possession.Remove(client.Avatar.Id);
                }
                World.Possession[avatar.Id] = client;
                client.Avatar = avatar;
                client.LogMessage("You are now controlling " + avatar);
            }
            else
            {
                // try to load the character
                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 CombatantModel(
                        Global.Rand.Next(), client.AuthenticatedUsername, "RTSRobot",
                        new Vector3D(), Quaternion.Identity, 100, 100, Common.EnumMobileState.Standing, 1.7f,
                        20, 20, 20, 20, 20);
                }

                World.Possession[avatar.Id] = client;
                client.Avatar = avatar;

                // try to add the character to the world
                World.Apply(new EntityUpdateEvent(avatar, "Loaded for possession"));
            }
            World.SendInitialWorldView(client);
        }