public static EquippedObject CreateDurableObject(string value)
    {
        EquippedObject equippedObject = new EquippedObject();

        equippedObject.equippedObjectType = "durable";
        equippedObject.EquippedObjectId   = value;
        return(equippedObject);
    }
    public static EquippedObject CreateDispensableObject(string dispensableId)
    {
        EquippedObject equippedObject = new EquippedObject();

        equippedObject.equippedObjectType = "dispns";
        equippedObject.EquippedObjectId   = dispensableId;
        return(equippedObject);
    }
    public static EquippedObject CreateConsumableObject(string consumableId)
    {
        EquippedObject equippedObject = new EquippedObject();

        equippedObject.equippedObjectType = "consum";
        equippedObject.EquippedObjectId   = consumableId;
        return(equippedObject);
    }
    public static EquippedObject FromSFSData(ISFSObject obj, string properties = null)
    {
        EquippedObject equippedObject = new EquippedObject();

        equippedObject.equippedObjectType = obj.GetUtfString("type");
        equippedObject.EquippedObjectId   = obj.GetUtfString("name");
        equippedObject.PropertiesJSON     = properties;
        return(equippedObject);
    }
Beispiel #5
0
 public void EquipConsumable(string type)
 {
     updateUserVars(new Dictionary <SocketUserVars, object> {
         {
             SocketUserVars.EQUIPPED_OBJECT,
             EquippedObject.CreateConsumableObject(type).ToSFSObject()
         }
     });
 }
Beispiel #6
0
 public AwayFromKeyboardStateChanged(long sessionId, int value, EquippedObject equippedObject)
 {
     SessionId      = sessionId;
     Value          = value;
     EquippedObject = equippedObject;
 }
Beispiel #7
0
        private void broadcastUserVariables(User user, ArrayList changedVars = null)
        {
            bool flag = getSessionId(user) == mt.ClubPenguinClient.PlayerSessionId;

            if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.PROTOTYPE.GetKey())) && user.ContainsVariable(SocketUserVars.PROTOTYPE.GetKey()))
            {
                PrototypeState prototypeState = default(PrototypeState);
                prototypeState.id   = getSessionId(user);
                prototypeState.data = JsonMapper.ToObject(user.GetVariable(SocketUserVars.PROTOTYPE.GetKey()).GetStringValue());
                mt.triggerEvent(GameServerEvent.PROTOTYPE_STATE, prototypeState);
            }
            if (changedVars == null || changedVars.Contains(SocketUserVars.EQUIPPED_OBJECT.GetKey()))
            {
                UserVariable variable  = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT.GetKey());
                UserVariable variable2 = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT_PROPERTIES.GetKey());
                if (variable == null)
                {
                    if (changedVars != null && changedVars.Contains(SocketUserVars.EQUIPPED_OBJECT_PROPERTIES.GetKey()) && variable2 == null)
                    {
                        mt.triggerEvent(GameServerEvent.SERVER_ITEM_REMOVED, new CPMMOItemId(getSessionId(user), CPMMOItemId.CPMMOItemParent.PLAYER));
                    }
                    else
                    {
                        mt.triggerEvent(GameServerEvent.HELD_OBJECT_DEQUIPPED, getSessionId(user));
                    }
                }
                else
                {
                    EquippedObject equippedObject = EquippedObject.FromSFSData(variable.GetSFSObjectValue());
                    if (variable2 != null)
                    {
                        PlayerHeldItem playerHeldItem = new PlayerHeldItem();
                        playerHeldItem.Id         = new CPMMOItemId(getSessionId(user), CPMMOItemId.CPMMOItemParent.PLAYER);
                        playerHeldItem.CreatorId  = playerHeldItem.Id.Id;
                        playerHeldItem.Type       = equippedObject.EquippedObjectId;
                        playerHeldItem.Properties = variable2.GetStringValue();
                        mt.triggerEvent(GameServerEvent.SERVER_ITEM_ADDED, playerHeldItem);
                    }
                    else if (!flag || (flag && equippedObject.isPartyGame()))
                    {
                        HeldObjectEvent heldObjectEvent = default(HeldObjectEvent);
                        heldObjectEvent.SessionId = getSessionId(user);
                        heldObjectEvent.Type      = equippedObject.EquippedObjectId;
                        if (equippedObject.IsConsumable())
                        {
                            mt.triggerEvent(GameServerEvent.CONSUMABLE_EQUIPPED, heldObjectEvent);
                        }
                        else if (equippedObject.IsDispensable())
                        {
                            mt.triggerEvent(GameServerEvent.DISPENSABLE_EQUIPPED, heldObjectEvent);
                        }
                        else if (equippedObject.IsDurable())
                        {
                            mt.triggerEvent(GameServerEvent.DURABLE_EQUIPPED, heldObjectEvent);
                        }
                        else if (equippedObject.isPartyGame())
                        {
                            mt.triggerEvent(GameServerEvent.PARTYGAME_EQUIPPED, heldObjectEvent);
                        }
                    }
                }
            }
            else if (changedVars.Contains(SocketUserVars.EQUIPPED_OBJECT_PROPERTIES.GetKey()))
            {
                UserVariable variable3 = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT.GetKey());
                if (variable3 != null && variable3.Type == VariableType.OBJECT)
                {
                    PlayerHeldItem playerHeldItem = new PlayerHeldItem();
                    playerHeldItem.Id         = new CPMMOItemId(getSessionId(user), CPMMOItemId.CPMMOItemParent.PLAYER);
                    playerHeldItem.CreatorId  = playerHeldItem.Id.Id;
                    playerHeldItem.Type       = EquippedObject.FromSFSData(variable3.GetSFSObjectValue()).EquippedObjectId;
                    playerHeldItem.Properties = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT_PROPERTIES.GetKey()).GetStringValue();
                    mt.triggerEvent(GameServerEvent.SERVER_ITEM_CHANGED, playerHeldItem);
                }
            }
            if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.LOCOMOTION_STATE.GetKey())))
            {
                UserVariable variable4 = user.GetVariable(SocketUserVars.LOCOMOTION_STATE.GetKey());
                PlayerLocomotionStateEvent playerLocomotionStateEvent = default(PlayerLocomotionStateEvent);
                playerLocomotionStateEvent.SessionId = getSessionId(user);
                if (variable4 == null || variable4.IsNull())
                {
                    playerLocomotionStateEvent.State = LocomotionState.Default;
                }
                else
                {
                    playerLocomotionStateEvent.State = (LocomotionState)variable4.GetIntValue();
                }
                mt.triggerEvent(GameServerEvent.USER_LOCO_STATE_CHANGED, playerLocomotionStateEvent);
            }
            if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.OUTFIT.GetKey())) && user.ContainsVariable(SocketUserVars.OUTFIT.GetKey()))
            {
                PlayerOutfitDetails playerOutfitDetails = mt.JsonService.Deserialize <PlayerOutfitDetails>(user.GetVariable(SocketUserVars.OUTFIT.GetKey()).GetStringValue());
                playerOutfitDetails.sessionId = getSessionId(user);
                mt.triggerEvent(GameServerEvent.USER_OUTFIT_CHANGED, playerOutfitDetails);
            }
            if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.PROFILE.GetKey())) && user.ContainsVariable(SocketUserVars.PROFILE.GetKey()))
            {
                ProfileEvent profileEvent = default(ProfileEvent);
                profileEvent.SessionId      = getSessionId(user);
                profileEvent.Profile        = new Profile();
                profileEvent.Profile.colour = user.GetVariable(SocketUserVars.PROFILE.GetKey()).GetIntValue();
                mt.triggerEvent(GameServerEvent.USER_PROFILE_CHANGED, profileEvent);
            }
            if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.AIR_BUBBLE.GetKey())))
            {
                UserVariable         variable5            = user.GetVariable(SocketUserVars.AIR_BUBBLE.GetKey());
                PlayerAirBubbleEvent playerAirBubbleEvent = default(PlayerAirBubbleEvent);
                playerAirBubbleEvent.SessionId = getSessionId(user);
                if (variable5 == null || variable5.IsNull())
                {
                    playerAirBubbleEvent.AirBubble = new AirBubble();
                }
                else
                {
                    playerAirBubbleEvent.AirBubble = AirBubble.FromSFSData(variable5.GetSFSObjectValue());
                }
                mt.triggerEvent(GameServerEvent.AIR_BUBBLE_UPDATE, playerAirBubbleEvent);
            }
            if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.ON_QUEST.GetKey())))
            {
                UserVariable variable4    = user.GetVariable(SocketUserVars.ON_QUEST.GetKey());
                OnQuestState onQuestState = default(OnQuestState);
                onQuestState.SessionId = getSessionId(user);
                if (!(variable4?.IsNull() ?? true))
                {
                    onQuestState.MascotName = variable4.GetStringValue();
                }
                mt.triggerEvent(GameServerEvent.ON_QUEST, onQuestState);
            }
            if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.SELECTED_TUBE.GetKey())) && user.ContainsVariable(SocketUserVars.SELECTED_TUBE.GetKey()))
            {
                SelectedTubeEvent selectedTubeEvent = default(SelectedTubeEvent);
                selectedTubeEvent.SessionId = getSessionId(user);
                selectedTubeEvent.TubeId    = user.GetVariable(SocketUserVars.SELECTED_TUBE.GetKey()).GetIntValue();
                mt.triggerEvent(GameServerEvent.SELECTED_TUBE_CHANGED, selectedTubeEvent);
            }
            if (!flag && (changedVars == null || changedVars.Contains(SocketUserVars.TEMPORARY_HEAD_STATUS.GetKey())) && user.ContainsVariable(SocketUserVars.TEMPORARY_HEAD_STATUS.GetKey()))
            {
                TemporaryHeadStatusEvent temporaryHeadStatusEvent = default(TemporaryHeadStatusEvent);
                temporaryHeadStatusEvent.SessionId = getSessionId(user);
                temporaryHeadStatusEvent.Type      = user.GetVariable(SocketUserVars.TEMPORARY_HEAD_STATUS.GetKey()).GetIntValue();
                mt.triggerEvent(GameServerEvent.TEMPORARY_HEAD_STATUS_CHANGED, temporaryHeadStatusEvent);
            }
            if (flag || (changedVars != null && !changedVars.Contains(SocketUserVars.AWAY_FROM_KEYBOARD.GetKey())))
            {
                return;
            }
            UserVariable variable6 = user.GetVariable(SocketUserVars.AWAY_FROM_KEYBOARD.GetKey());

            if (variable6 == null || variable6.IsNull())
            {
                EquippedObject equippedObject2 = null;
                UserVariable   variable7       = user.GetVariable(SocketUserVars.EQUIPPED_OBJECT.GetKey());
                if (variable7 != null)
                {
                    equippedObject2 = EquippedObject.FromSFSData(variable7.GetSFSObjectValue());
                }
                mt.triggerEvent(GameServerEvent.AWAY_FROM_KEYBOARD_STATE_CHANGED, new AFKEvent(getSessionId(user), 0, equippedObject2));
            }
            else
            {
                mt.triggerEvent(GameServerEvent.AWAY_FROM_KEYBOARD_STATE_CHANGED, new AFKEvent(getSessionId(user), variable6.GetIntValue(), null));
            }
        }
 public AwayFromKeyboardState(AwayFromKeyboardStateType type, EquippedObject equippedObject)
 {
     Type           = type;
     EquippedObject = equippedObject;
 }
        public override bool FireEvent(Event E)
        {
            if (E.ID == "BeforeApplyDamage")
            {
                Damage parameter = E.GetParameter("Damage") as Damage;
                if (!(parameter.HasAttribute("Electric") || parameter.HasAttribute("Shock") || parameter.HasAttribute("Lightning") || parameter.HasAttribute("Electricity")))
                {
                    return(true);
                }

                double ReductionDouble = (double)parameter.Amount * GetPercentageResist(this.Level);
                int    Reduction       = (int)Math.Floor(ReductionDouble);
                if (ReductionDouble - (double)Reduction >= Stat.Rnd.NextDouble())
                {
                    Reduction += 1;
                }
                if (Reduction > 0 && this.ParentObject.IsPlayer())
                {
                    MessageQueue.AddPlayerMessage("Your scales absorb " + Reduction.ToString() + " damage from the electricity.");
                }
                parameter.Amount = Math.Max(0, parameter.Amount - Reduction);
                return(false);
            }
            if (E.ID == "EndTurn" && this.ChargeCellsActivatedAbility != null && this.ChargeCellsActivatedAbility.ToggleState)
            {
                foreach (GameObject EquippedObject in this.ParentObject.GetPart <Body>().GetEquippedObjects())
                {
                    if (EquippedObject == null)
                    {
                        continue;
                    }

                    EnergyCell Cell = null;
                    if (EquippedObject != null && EquippedObject.HasPart("EnergyCell"))
                    {
                        Cell = EquippedObject.GetPart <EnergyCell>();
                    }
                    else if (EquippedObject.HasPart("EnergyCellSocket"))
                    {
                        EnergyCellSocket Socket = this.ParentObject.GetPart <EnergyCellSocket>();
                        if (Socket.Cell != null && Socket.Cell.HasPart("EnergyCell"))
                        {
                            Cell = Socket.Cell.GetPart <EnergyCell>();
                        }
                    }

                    if (Cell != null && Cell.CanBeRecharged() && Cell.GetRechargeAmount() > 0)
                    {
                        // Cells have varying degrees of charge rates so we need to
                        int RechargedAmount = ConsumeCharge(Math.Min(Cell.GetRechargeAmount(), Cell.ChargeRate));
                        if (RechargedAmount == 0) // hungry....
                        {
                            if (this.ParentObject.IsPlayer())
                            {
                                MessageQueue.AddPlayerMessage("You're too hungry to muster any more energy...");
                            }
                            this.ChargeCellsActivatedAbility.ToggleState = false;
                            break;
                        }
                        else
                        {
                            Cell.AddCharge(RechargedAmount);
                        }
                    }
                }
            }
            return(base.FireEvent(E));
        }
Beispiel #10
0
 public AFKEvent(long sessionId, int afkValue, EquippedObject equippedObject)
 {
     SessionId      = sessionId;
     AFKValue       = afkValue;
     EquippedObject = equippedObject;
 }