public virtual void LoadAllQuestsAndAchievementsFor(ILocalIdentifier localIdentifier)
        {
            var db    = QuestManager.instance.GetQuestStates(localIdentifier);
            var model = LoadQuestsContainerModel(PlayerPrefsQuestStatesKey + localIdentifier.ToString());

            // TODO: In the future we'd probably want to make a copy of the quest (QuestManager.instance.quests ..) and add that to the player's quest states.
            foreach (var quest in model.activeQuests)
            {
                LoadSerializationModelToSource(quest, QuestManager.instance.quests.FirstOrDefault(o => o.ID == quest.ID), db.activeQuests);
            }

            foreach (var quest in model.completedQuests)
            {
                LoadSerializationModelToSource(quest, QuestManager.instance.quests.FirstOrDefault(o => o.ID == quest.ID), db.completedQuests);
            }

            foreach (var achievement in model.achievements)
            {
                LoadSerializationModelToSource(achievement, QuestManager.instance.achievements.FirstOrDefault(o => o.ID == achievement.ID), db.achievements);
            }


            DevdogLogger.LogVerbose("Deserialized active quests: " + model.activeQuests.Length + " for " + localIdentifier.ToString());
            DevdogLogger.LogVerbose("Deserialized completed quests: " + model.completedQuests.Length + " for " + localIdentifier.ToString());
            DevdogLogger.LogVerbose("Deserialized achievements: " + model.achievements.Length + " for " + localIdentifier.ToString());
        }
        public void RegisterPickup(UFPSInventoryItemBase item)
        {
            item.itemPickup.ID = (vp_Utility.PositionToID(item.itemPickup.transform.position) + ((int)item.ID * 100000));
            RegisterPickup(item.itemPickup);

            DevdogLogger.LogVerbose("Registered item with UFPS multiplayer. New UFPS ID: " + item.itemPickup.ID, item);
        }
 protected virtual void Init()
 {
     // Everytime the items are generated the clients should request the new item list + index them with UFPS (InventoryMPUFPSPickupManager.instance.RegisterPickup)
     // otherwise replication will fail.
     DevdogLogger.LogVerbose("Requesting item list (initial) - (isMaster: " + PhotonNetwork.isMasterClient + ")");
     photonView.RPC("RequestLootableItems", PhotonTargets.MasterClient);
 }
        public override void Load()
        {
            try
            {
                LoadItems((data) =>
                {
                    DevdogLogger.LogVerbose("Loaded container " + saveName);

                    var model = serializer.DeserializeContainer(data);
                    model.ToContainer(container);
                    foreach (var item in container.items)
                    {
                        if (item != null)
                        {
                            item.gameObject.SetActive(false);
                            item.transform.SetParent(transform);
                            item.transform.localPosition = Vector3.zero;
                        }
                    }
                });
            }
            catch (SerializedObjectNotFoundException e)
            {
                Debug.LogWarning(e.Message + e.StackTrace);
            }
        }
        public override void Load()
        {
            try
            {
                LoadItems((object data) =>
                {
                    DevdogLogger.LogVerbose("Loaded collection " + collection.collectionName);

                    var model = serializer.DeserializeCollection(data);
                    model.ToCollection(collection);

                    var character = this.collection.GetComponent <ICharacterCollection>();
                    // Are we loading items to a character collection?
                    if (character != null)
                    {
                        // if so, go through the items and
                        foreach (var slot in collection.items)
                        {
                            var equippedItem = slot.item as EquippableInventoryItem;

                            // if they must be equipped visually, do so
                            if (equippedItem != null && equippedItem.equipVisually)
                            {
                                character.character.equipmentHandler.EquipItemVisually(equippedItem, character.equippableSlots[equippedItem.index]);
                            }
                        }
                    }
                });
            }
            catch (SerializedObjectNotFoundException e)
            {
                Debug.LogWarning(e.Message + e.StackTrace);
            }
        }
Example #6
0
        public virtual bool CanSetTaskProgress(string key, float value)
        {
            if (status != QuestStatus.Active)
            {
                DevdogLogger.LogVerbose("Trying to set progress on quest task but quest is not active. Setting progress ignored status is: " + status);
                return(false);
            }

            if (taskOrder == TaskOrder.Single)
            {
                var setProgressTask = GetTask(key);
                foreach (var task in tasks)
                {
                    if (task == setProgressTask)
                    {
                        break;
                    }

                    if (task.isCompleted == false)
                    {
                        DevdogLogger.LogVerbose("Task is not completed: " + task.key);
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #7
0
        public virtual EquippableSlot GetBestEquipSlot(ICharacterCollection equipCollection)
        {
            Assert.IsNotNull(equipCollection);

            var equipSlots = equipCollection.GetEquippableSlots(this);

            if (equipSlots.Length == 0)
            {
                DevdogLogger.LogVerbose("No equipment location found for item: #" + ID + " " + name);
                return(null);
            }

            EquippableSlot equipSlot = equipSlots[0];

            foreach (var e in equipSlots)
            {
                if (equipCollection.equippableSlots[e.index].slot.item == null)
                {
                    equipSlot = e; // Prefer an empty slot over swapping a filled one.
                    break;
                }
            }

            return(equipSlot);
        }
        protected virtual void HandleSkinnedMeshes(EquippableInventoryItem copy, CharacterEquipmentTypeBinder binder)
        {
            if (binder.equipTransform == null)
            {
                return;
            }

            if (replaceSkinnedMeshBones)
            {
                var itemSkinned = copy.GetComponentInChildren <SkinnedMeshRenderer>();
                if (itemSkinned != null)
                {
                    // It's a skinned mesh, combine the bones of this mesh with the player's bones to sync animations.
                    var playerSkinned = binder.equipTransform.GetComponentInParent <SkinnedMeshRenderer>();
                    if (playerSkinned != null)
                    {
                        itemSkinned.rootBone = binder.rootBone;

                        if (forceReplaceAllBones)
                        {
                            itemSkinned.bones = playerSkinned.bones;
                            DevdogLogger.LogVerbose("Force copied " + itemSkinned.bones.Length + " bones to new skinned mesh", itemSkinned);
                        }
                        else
                        {
                            ReplaceBonesOnTarget(playerSkinned, itemSkinned);
                        }
                    }
                    else
                    {
                        DevdogLogger.LogWarning("Tried to equip skinned item to player, but no skinned mesh renderer found in equip position's parent.", binder.equipTransform);
                    }
                }
            }
        }
Example #9
0
        /// <summary>
        /// Initialize this player. The player will be added to the players list ( assigned to the InventoryPlayerManager )
        /// </summary>
        public virtual void Init()
        {
            Assert.IsFalse(isInitialized, "Tried to initialize player - Player was already initialized!");
            DevdogLogger.LogVerbose("Initializing InventoryPlayer", this);
            isInitialized = true;

            UpdateEquipLocations(transform);

            stats.dataProviders.Add(new StatsProvider());
            stats.Prepare();

            if (dontDestroyOnLoad)
            {
                gameObject.AddComponent <DontDestroyOnLoad>();
            }

            if (dynamicallyFindUIElements)
            {
                FindUIElements();
            }

            if (characterUI != null)
            {
                characterUI.character = this;
                equipmentHandler.Init(characterUI);
            }

            SetAsActivePlayer();
        }
Example #10
0
        /// <summary>
        /// Fill this data model with a collection reference.
        /// Gets the collection data from the collection and stores it in this serializable model.
        /// </summary>
        public void FromContainer(IInventoryItemContainer container)
        {
            // Serialize based on inventory item serialization model.
            items = new InventoryItemSerializationModel[container.items.Length];
            for (int i = 0; i < container.items.Length; i++)
            {
                var item = container.items[i];
                InventoryItemSerializationModel inst = null;
                if (item != null)
                {
                    var  classes            = ReflectionUtility.GetAllClassesWithAttribute(typeof(SerializationModelAttribute), true);
                    Type serializationModel = typeof(InventoryItemSerializationModel);

                    foreach (var c in classes)
                    {
                        var attrib = (SerializationModelAttribute)c.GetCustomAttributes(typeof(SerializationModelAttribute), true).First();
                        if (c == item.GetType())
                        {
                            DevdogLogger.LogVerbose("Using custom serialization model for " + item.GetType().Name + " - " + attrib.type.Name);
                            serializationModel = attrib.type;
                        }
                    }

                    inst = (InventoryItemSerializationModel)Activator.CreateInstance(serializationModel);
                    inst.FromItem(item);
                }
                else
                {
                    inst = new InventoryItemSerializationModel(null);
                }

                items[i] = inst;
            }
        }
        public bool OnTriggerUnUsed(Player player)
        {
            DevdogLogger.LogVerbose("Client un-used trigger -> Notify other clients", player);
            photonView.RPC("OnTriggerUnUsedByOtherClient", PhotonTargets.Others);

            return(false);
        }
        private void RequestLootableItems(PhotonMessageInfo info)
        {
            DevdogLogger.LogVerbose("[Server] LootableObject - Client requested LootableObject item list", this);

            string result = GetItemsAsNetworkString();

            photonView.RPC("SetLootableItems", info.sender, result);
        }
Example #13
0
        public IEnumerator PerformActionsAtWaypoint(Waypoint waypoint, IWaypointCharacter character)
        {
            DevdogLogger.LogVerbose("(start) Wait at waypoint action", character.transform);
            character.characterController.Stop();
            yield return(_waitTime);

            character.characterController.Resume();
        }
Example #14
0
        protected virtual void OnGUI()
        {
            searchQuery = EditorStyles.SearchBar(searchQuery, this, isSearching);

            foreach (var kvp in lookups)
            {
                if (isSearching)
                {
                    if (kvp.Value.Any(o => o.Name.ToLower().Contains(searchQuery.ToLower())) == false)
                    {
                        continue;
                    }
                }
                else
                {
                    GUI.color = Color.cyan;

                    if (GUILayout.Button(kvp.Key, expandedKeys.Contains(kvp.Key) ? normalButtonStyle : selectedButtonStyle))
                    {
                        if (expandedKeys.Contains(kvp.Key))
                        {
                            expandedKeys.Remove(kvp.Key);
                        }
                        else
                        {
                            expandedKeys.Add(kvp.Key);
                        }
                    }
                }

                GUI.color = Color.white;

                if (expandedKeys.Contains(kvp.Key) || isSearching)
                {
                    foreach (var type in lookups[kvp.Key])
                    {
                        EditorGUILayout.BeginHorizontal();

                        GUILayout.Space(20);
                        if (GUILayout.Button(type.Name))
                        {
                            var node = DialogueEditorWindow.CreateAndAddNodeToCurrentDialog(type);
                            if (node != null)
                            {
                                DevdogLogger.LogVerbose("Add new node of type " + type.Name + " with index: " + node.index);
                            }
                            else
                            {
                                DevdogLogger.Log("Couldn't add node, no dialogue selected.");
                            }
                        }

                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
        }
Example #15
0
        public void UseWaypointGroup(WaypointGroup group, int startWaypointIndex)
        {
            Assert.IsNotNull(group);

            this.waypointGroup   = group;
            currentWaypointIndex = startWaypointIndex;

            DevdogLogger.LogVerbose("Waypoint character controller is following new WaypointGroup", this);
        }
        public override bool HasCompletedQuest(Quest quest)
        {
            DevdogLogger.LogVerbose("Checking server ... ");
            CmdHasCompletedQuest(quest);

            bool completed = questStates[quest.localIdentifier].completedQuests.Contains(quest);

            return(completed);
        }
Example #17
0
        public void OnReachedTimeLimit(Task task)
        {
            task.Fail();

            if (failQuestWhenOutOfTime)
            {
                DevdogLogger.LogVerbose("Quest cancelled because time limit was reached on required task (" + task.key + ").");
                task.owner.Cancel();
            }
        }
Example #18
0
        public virtual bool OnTriggerUnUsed(Player player)
        {
            if (dialogue != null)
            {
                dialogue.Stop();
            }

            DevdogLogger.LogVerbose("DialogueOwner consumed trigger callback UnUse()", this);
            return(true); // Dialogue owner consumes the event to avoid others also receiving the trigger used events.
        }
Example #19
0
        public override bool SetTaskProgress(string key, float value)
        {
            if (status == QuestStatus.InActive || status == QuestStatus.Cancelled)
            {
                DevdogLogger.LogVerbose("Setting achievement task progress, but achievement was not activated yet. Auto. activating achievement...");
                Activate();
            }

            return(base.SetTaskProgress(key, value));
        }
Example #20
0
        public virtual bool CanSetTaskProgress(string key, float value)
        {
            if (status != QuestStatus.Active)
            {
                DevdogLogger.LogVerbose("Trying to set progress on quest task but quest is not active. Setting progress ignored status is: " + status);
                return(false);
            }

            return(true);
        }
        public void Unlock(IStat parent)
        {
#if UNITY_EDITOR
            DevdogLogger.LogVerbose("Unlocked stat level on stat: " + parent.definition.statName + " Level is now: " + parent.definition.levels.ToList().IndexOf(this));
#endif
            if (effectOnUnlock != null)
            {
                UnityEngine.Object.Instantiate <GameObject>(effectOnUnlock);
            }
        }
        protected void _NotifyQuestStatusChanged(QuestStatus before, Quest quest)
        {
            DevdogLogger.LogVerbose("(Server) Quest " + quest.name + " status changed to " + quest.status);

            if (quest.status == QuestStatus.Completed)
            {
                questStates[quest.localIdentifier].completedQuests.Add(quest);
                DevdogLogger.LogVerbose("(Server) Completed quest " + quest.name);
            }
        }
        public IEnumerator PerformActionsAtWaypoint(Waypoint waypoint, IWaypointCharacter character)
        {
            DevdogLogger.LogVerbose("(start) Wait for player waypoint action", character.transform);
            character.characterController.Stop();

            while ((PlayerManager.instance.currentPlayer.transform.position - character.transform.position).sqrMagnitude > 9f)
            {
                yield return(_waitTime);
            }

            character.characterController.Resume();
        }
Example #24
0
        public void GiveRewards(Quest quest)
        {
            var task = quest.GetTask(taskName);

            if (task == null)
            {
                DevdogLogger.LogWarning("Task " + taskName + " not found on quest " + quest);
                return;
            }

            task.timeLimitInSeconds += addTimeInSeconds;
            DevdogLogger.LogVerbose("Gave task " + taskName + " " + addTimeInSeconds + " extra seconds (rewardGiver)");
        }
        public IEnumerator PerformActionsAtWaypoint(Waypoint waypoint, IWaypointCharacter character)
        {
            DevdogLogger.LogVerbose("(start) Use trigger waypoint action", character.transform);
            character.characterController.SetDestination(trigger.transform.position);

            // Wait to reach trigger.
            while (character.characterController.distanceToDestination > useDistance)
            {
                yield return(null);
            }

            DevdogLogger.LogVerbose("(complete) Force use trigger", character.transform);
            trigger.ForceUseWithoutStateAndUI(character.transform.gameObject);
        }
 public override void Save()
 {
     try
     {
         SaveItems(serializer.SerializeContainer(container), (bool saved) =>
         {
             DevdogLogger.LogVerbose("Saved container " + saveName);
         });
     }
     catch (SerializedObjectNotFoundException e)
     {
         Debug.LogWarning(e.Message + e.StackTrace);
     }
 }
        public bool OnTriggerUsed(Player player)
        {
            if (PhotonNetwork.isMasterClient == false)
            {
                _lootable.items = new InventoryItemBase[0]; // Clear the items, wait for the server to respond with the item list.
            }

            // Make sure we're up to date.
            DevdogLogger.LogVerbose("Client used trigger -> Notify other clients + Requesting item list (isMaster: " + PhotonNetwork.isMasterClient + ")", player);
            photonView.RPC("RequestLootableItems", PhotonTargets.MasterClient);
            photonView.RPC("OnTriggerUsedByOtherClient", PhotonTargets.Others);

            return(false);
        }
        private void LootableObjectItemRemoved(int slot, PhotonMessageInfo info)
        {
            DevdogLogger.LogVerbose("[Client] LootableObject - Other client looted slot: " + slot, transform);
            if (slot < 0 || slot >= _lootable.items.Length)
            {
                UnityEngine.Debug.LogWarning("Item is out of range " + slot + " can't set item");
                return;
            }

            _lootable.items[slot] = null;
            if (_lootable.lootUI.items.Length == _lootable.items.Length)
            {
                _lootable.lootUI.SetItem((uint)slot, null, true);
            }
        }
 public override void Save()
 {
     try
     {
         var serializedCollection = serializer.SerializeCollection(collection);
         SaveItems(serializedCollection, (bool saved) =>
         {
             DevdogLogger.LogVerbose("Saved collection " + collection.collectionName);
         });
     }
     catch (SerializedObjectNotFoundException e)
     {
         Debug.LogWarning(e.Message + e.StackTrace);
     }
 }
Example #30
0
        public static Variable Get(Guid g)
        {
            DevdogLogger.LogVerbose("Getting variable with GUID: " + g + " Looking through " + variableContainers.Count + " containers.");
            foreach (var container in variableContainers)
            {
                var v = container.Get(g);
                if (v != null)
                {
                    return(v);
                }
            }

            DevdogLogger.LogWarning("Trying to get variable with GUID " + g + " - Not found.");
            return(null);
        }