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 #2
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);
        }
Example #3
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 #4
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 virtual void InitSightTrigger()
        {
            _sightTrigger = GetComponentInChildren <SphereCollider>();
            if (_sightTrigger == null)
            {
                var obj = new GameObject("_Col");
                obj.transform.SetParent(transform, false);
                _sightTrigger = obj.AddComponent <SphereCollider>();
            }

            _sightTrigger.isTrigger = true;
            _sightTrigger.radius    = config.viewingDistance;
            _sightTrigger.GetOrAddComponent <ObserverTriggerHelperBehaviour>();
            var r = _sightTrigger.GetOrAddComponent <Rigidbody>();

            r.useGravity  = false;
            r.isKinematic = true;

            if (LosManager.instance.settings != null)
            {
                _sightTrigger.gameObject.layer = LosManager.instance.settings.sightLayerID;
            }
            else
            {
                DevdogLogger.LogWarning("Settings database not set on LosManager");
            }
        }
        public override int Use()
        {
            int used = base.Use();

            if (used < 0)
            {
                return(used); // Item cannot be used
            }
            var extenderCollection = GetExtenderCollection();

            if (extenderCollection == null)
            {
                DevdogLogger.LogWarning("Can't use bag, no collection found with interface " + typeof(ICollectionExtender));
                return(-2);
            }

            bool added = extenderCollection.extenderCollection.AddItemAndRemove(this);

            if (added)
            {
                return(1);
            }

            return(-2);
        }
Example #7
0
        //[ServerCallback]
        public void OnTriggerUsed(Character character, TriggerEventData eventData)
        {
            if (!PhotonNetwork.LocalPlayer.IsMasterClient)
            {
                return;
            }

            var bridge = character.GetComponent <PUN2ActionsBridge>();

            if (character is Player && bridge != null)
            {
                var inst  = ItemFactory.CreateInstance(itemDefinition, System.Guid.NewGuid());
                var added = bridge.inventoryPlayer.itemCollectionGroup.Add(inst, amount);
                if (added.error != null)
                {
                    // Something went wrong, remove item from registry to avoid cluttering it with un-used items.
                    ServerItemRegistry.UnRegister(inst.ID);
                    ItemRegistry.UnRegister(inst.ID);

                    // TODO: Notify client why pickup failed

                    DevdogLogger.LogError($"[PUN2][Interaction] PUN2ItemPickup.OnTriggerUsed: {added.error}", this);
                }
                else
                {
                    // Action went succesful, destroy pickup source
                    //NetworkServer.Destroy(gameObject);
                    //PhotonNetwork.Destroy(gameObject);
                    //GameObject.Destroy(gameObject);

                    bridge.photonView.RPC(nameof(bridge.Cmd_RequestUnUseTrigger), PhotonNetwork.MasterClient, this.photonView.ViewID);
                    PhotonNetwork.Destroy(gameObject);
                }
            }
        }
        protected virtual void Kill()
        {
            if (isDead)
            {
                return;
            }

            isDead = true;
            DevdogLogger.Log("You killed it!");
            if (_onKilled != null)
            {
                _onKilled.OnKilled();
            }

            if (_agent.isOnNavMesh)
            {
#if UNITY_2017_1_OR_NEWER
                _agent.isStopped = true;
#else
                _agent.Stop();
#endif
            }

            StartCoroutine(SinkIntoGround());
        }
Example #9
0
        //[ServerCallback]
        public void OnTriggerUsed(Character character, TriggerEventData eventData)
        {
            if (!PhotonNetwork.LocalPlayer.IsMasterClient)
            {
                return;
            }

            var bridge = character.GetComponent <PUN2ActionsBridge>();

            if (character is Player && bridge != null)
            {
                var added = bridge.inventoryPlayer.itemCollectionGroup.Add(itemInstance, amount);
                if (added.error != null)
                {
                    // TODO: Notify client why pickup failed
                    DevdogLogger.LogError($"[PUN2][Interaction] PUN2ItemInstancePickup.OnTriggerUsed: {added.error}", this);
                }
                else
                {
                    // Action went succesful, destroy pickup source
                    //NetworkServer.Destroy(gameObject);
                    //PhotonNetwork.Destroy(gameObject);
                    //GameObject.Destroy(gameObject);

                    bridge.photonView.RPC(nameof(bridge.Cmd_RequestUnUseTrigger), PhotonNetwork.MasterClient, this.photonView.ViewID);
                    PhotonNetwork.Destroy(gameObject);
                }
            }
        }
Example #10
0
        public bool CompleteAndGiveRewards(bool forceComplete = false)
        {
            if (CanComplete() == false && forceComplete == false)
            {
                return(false);
            }

            // Even when forcing the quest CAN NOT be completed if the user can't get his/her rewards.
            if (CanGiveRewards() == false)
            {
                return(false);
            }

            repeatedTimes++;

            CompleteCompletableTasks(forceComplete);
            GiveRewards();

            status = repeatedTimes < maxRepeatTimes ? QuestStatus.InActive : QuestStatus.Completed;
            DevdogLogger.Log("Completed quest/achievement with ID: " + ID + " and gave rewards. Repeated quest #" + repeatedTimes + " times. Quest status is: " + status);

            NotifyTasksQuestCompleted();

            return(true);
        }
        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 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);
            }
        }
        public bool OnTriggerUnUsed(Player player)
        {
            DevdogLogger.LogVerbose("Client un-used trigger -> Notify other clients", player);
            photonView.RPC("OnTriggerUnUsedByOtherClient", PhotonTargets.Others);

            return(false);
        }
        protected void SubscribeToMailingList(string email)
        {
            string result = "";

            using (var client = new WebClient())
            {
                client.Headers[HttpRequestHeader.ContentType] = "application/json";
                result = client.UploadString(signupNewsletterApiUrl + "?email_address=" + email, "POST");
            }

            if (result.Contains("\"status\":\"subscribed\""))
            {
                subscribedWithEmail = email;
                DevdogLogger.Log("Successfully subscribed to mailing list :)");

                Repaint();
            }
            else
            {
                DevdogLogger.Log("Whoops something went wrong while subscribing");
                DevdogLogger.Log(result);
            }

            GetImages();
        }
 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);
 }
Example #16
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);
        }
        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);
        }
        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);
            }
        }
Example #19
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();
        }
        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 #21
0
 public static void SetLanguage(string lang)
 {
     _currentDatabase = FindLocalizationDatabaseByName(lang);
     if (_currentDatabase == null)
     {
         DevdogLogger.LogWarning("Couldn't find localization database with language identifier \"" + lang + "\"");
     }
 }
Example #22
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 #23
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 #25
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 #26
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);
            }
        }
Example #28
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));
        }
        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);
            }
        }
Example #30
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();
            }
        }