Esempio n. 1
0
        protected virtual void NetFuncNpcActivate(PackedUInt objectId)
        {
            if (!CanDoActions())
            {
                return;
            }

            NpcEntity npcEntity = null;

            if (!TryGetEntityByObjectId(objectId, out npcEntity))
            {
                return;
            }

            if (Vector3.Distance(CacheTransform.position, npcEntity.CacheTransform.position) > gameInstance.conversationDistance + 5f)
            {
                return;
            }

            currentNpcDialog = npcEntity.StartDialog;
            if (currentNpcDialog != null)
            {
                RequestShowNpcDialog(currentNpcDialog.DataId);
            }
        }
Esempio n. 2
0
        protected virtual void NetFuncReceiveGuildInvitation(PackedUInt objectId)
        {
            BasePlayerCharacterEntity playerCharacterEntity = null;

            if (!TryGetEntityByObjectId(objectId, out playerCharacterEntity))
            {
                return;
            }
            if (onShowGuildInvitationDialog != null)
            {
                onShowGuildInvitationDialog.Invoke(playerCharacterEntity);
            }
        }
Esempio n. 3
0
        protected virtual void NetFuncAcceptedDealingRequest(PackedUInt objectId)
        {
            BasePlayerCharacterEntity playerCharacterEntity = null;

            if (!TryGetEntityByObjectId(objectId, out playerCharacterEntity))
            {
                return;
            }
            if (onShowDealingDialog != null)
            {
                onShowDealingDialog.Invoke(playerCharacterEntity);
            }
        }
Esempio n. 4
0
        protected virtual void NetFuncSendGuildInvitation(PackedUInt objectId)
        {
            BasePlayerCharacterEntity targetCharacterEntity;

            if (!gameManager.CanSendGuildInvitation(this, objectId, out targetCharacterEntity))
            {
                return;
            }
            DealingCharacter = targetCharacterEntity;
            targetCharacterEntity.DealingCharacter = this;
            // Send receive guild invitation request to player
            targetCharacterEntity.RequestReceiveGuildInvitation(ObjectId);
        }
        protected virtual void NetFuncSendPartyInvitation(PackedUInt objectId)
        {
            BasePlayerCharacterEntity targetCharacterEntity = null;

            if (!GameManager.CanSendPartyInvitation(this, objectId, out targetCharacterEntity))
            {
                return;
            }
            CoCharacter = targetCharacterEntity;
            targetCharacterEntity.CoCharacter = this;
            // Send receive party invitation request to player
            targetCharacterEntity.RequestReceivePartyInvitation(ObjectId);
        }
Esempio n. 6
0
        protected void NetFuncSetTargetEntity(PackedUInt objectId)
        {
            if (objectId == 0)
            {
                SetTargetEntity(null);
            }
            BaseGameEntity tempEntity;

            if (!TryGetEntityByObjectId(objectId, out tempEntity))
            {
                return;
            }
            SetTargetEntity(tempEntity);
        }
Esempio n. 7
0
        protected virtual void NetFuncUnSummon(PackedUInt objectId)
        {
            var index = this.IndexOfSummon(objectId);

            if (index < 0)
            {
                return;
            }

            var summon = Summons[index];

            if (summon.type != SummonType.Pet)
            {
                return;
            }

            Summons.RemoveAt(index);
            summon.UnSummon(this);
        }
        protected virtual void NetFuncDestroyBuild(PackedUInt objectId)
        {
            if (!CanMoveOrDoActions())
            {
                return;
            }

            BuildingEntity buildingEntity = null;

            if (!TryGetEntityByObjectId(objectId, out buildingEntity))
            {
                return;
            }

            if (buildingEntity != null && buildingEntity.CreatorId.Equals(Id))
            {
                GameManager.DestroyBuildingEntity(buildingEntity.Id);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// This will be called at server to order character to pickup items
        /// </summary>
        /// <param name="objectId"></param>
        protected virtual void NetFuncPickupItem(PackedUInt objectId)
        {
            if (!CanMoveOrDoActions())
            {
                return;
            }

            ItemDropEntity itemDropEntity = null;

            if (!TryGetEntityByObjectId(objectId, out itemDropEntity))
            {
                return;
            }

            if (Vector3.Distance(CacheTransform.position, itemDropEntity.CacheTransform.position) > GameInstance.pickUpItemDistance + 5f)
            {
                return;
            }

            if (!itemDropEntity.IsAbleToLoot(this))
            {
                GameManager.SendServerGameMessage(ConnectionId, GameMessage.Type.NotAbleToLoot);
                return;
            }

            var itemDropData = itemDropEntity.dropData;

            if (!itemDropData.IsValid())
            {
                // Destroy item drop entity without item add because this is not valid
                itemDropEntity.NetworkDestroy();
                return;
            }
            var itemDataId = itemDropData.dataId;
            var level      = itemDropData.level;
            var amount     = itemDropData.amount;

            if (!IncreasingItemsWillOverwhelming(itemDataId, amount) && this.IncreaseItems(itemDataId, level, amount))
            {
                itemDropEntity.NetworkDestroy();
            }
        }
Esempio n. 10
0
        protected virtual void NetFuncDestroyBuilding(PackedUInt objectId)
        {
            if (!CanDoActions())
            {
                return;
            }

            BuildingEntity buildingEntity = null;

            if (!TryGetEntityByObjectId(objectId, out buildingEntity))
            {
                return;
            }

            // TODO: For now only creator can destroy building
            if (buildingEntity != null && buildingEntity.CreatorId.Equals(Id))
            {
                gameManager.DestroyBuildingEntity(buildingEntity.Id);
            }
        }
Esempio n. 11
0
        protected virtual void NetFuncCraftItemByWorkbench(PackedUInt objectId, int dataId)
        {
            if (!CanDoActions())
            {
                return;
            }

            WorkbenchEntity workbenchEntity = null;

            if (!TryGetEntityByObjectId(objectId, out workbenchEntity))
            {
                return;
            }

            if (Vector3.Distance(CacheTransform.position, workbenchEntity.CacheTransform.position) > gameInstance.conversationDistance + 5f)
            {
                return;
            }

            workbenchEntity.CraftItem(this, dataId);
        }
Esempio n. 12
0
        protected virtual void NetFuncToggleDoor(PackedUInt objectId)
        {
            if (!CanDoActions())
            {
                return;
            }

            DoorEntity doorEntity = null;

            if (!TryGetEntityByObjectId(objectId, out doorEntity))
            {
                return;
            }

            if (Vector3.Distance(CacheTransform.position, doorEntity.CacheTransform.position) > gameInstance.conversationDistance + 5f)
            {
                return;
            }

            doorEntity.IsOpen = !doorEntity.IsOpen;
        }
Esempio n. 13
0
        protected virtual void NetFuncOpenStorage(PackedUInt objectId)
        {
            if (!CanDoActions())
            {
                return;
            }

            StorageEntity storageEntity = null;

            if (!TryGetEntityByObjectId(objectId, out storageEntity))
            {
                return;
            }

            if (Vector3.Distance(CacheTransform.position, storageEntity.CacheTransform.position) > gameInstance.conversationDistance + 5f)
            {
                return;
            }

            OpenStorage(StorageType.Building, storageEntity.Id);
        }
Esempio n. 14
0
        /// <summary>
        /// This will be called at server to order character to pickup items
        /// </summary>
        /// <param name="objectId"></param>
        protected virtual void NetFuncPickupItem(PackedUInt objectId)
        {
            if (!CanDoActions())
            {
                return;
            }

            ItemDropEntity itemDropEntity = null;

            if (!TryGetEntityByObjectId(objectId, out itemDropEntity))
            {
                return;
            }

            if (Vector3.Distance(CacheTransform.position, itemDropEntity.CacheTransform.position) > gameInstance.pickUpItemDistance + 5f)
            {
                return;
            }

            if (!itemDropEntity.IsAbleToLoot(this))
            {
                gameManager.SendServerGameMessage(ConnectionId, GameMessage.Type.NotAbleToLoot);
                return;
            }

            CharacterItem itemDropData = itemDropEntity.dropData;

            if (!itemDropData.NotEmptySlot())
            {
                // Destroy item drop entity without item add because this is not valid
                itemDropEntity.MarkAsPickedUp();
                itemDropEntity.NetworkDestroy();
                return;
            }
            if (!this.IncreasingItemsWillOverwhelming(itemDropData.dataId, itemDropData.amount) && this.IncreaseItems(itemDropData))
            {
                itemDropEntity.MarkAsPickedUp();
                itemDropEntity.NetworkDestroy();
            }
        }
Esempio n. 15
0
        protected virtual void NetFuncOpenBuildingStorage(PackedUInt objectId)
        {
            if (!CanDoActions())
            {
                return;
            }

            BuildingEntity buildingEntity = null;

            if (!TryGetEntityByObjectId(objectId, out buildingEntity))
            {
                return;
            }

            // TODO: For now only creator can open storage
            if (buildingEntity != null &&
                buildingEntity.CreatorId.Equals(Id) &&
                buildingEntity is StorageEntity)
            {
                OpenStorage(StorageType.Building, buildingEntity.Id);
            }
        }
Esempio n. 16
0
        protected virtual void NetFuncSendDealingRequest(PackedUInt objectId)
        {
            BasePlayerCharacterEntity targetCharacterEntity = null;

            if (!TryGetEntityByObjectId(objectId, out targetCharacterEntity))
            {
                gameManager.SendServerGameMessage(ConnectionId, GameMessage.Type.NotFoundCharacter);
                return;
            }
            if (targetCharacterEntity.DealingCharacter != null)
            {
                gameManager.SendServerGameMessage(ConnectionId, GameMessage.Type.CharacterIsInAnotherDeal);
                return;
            }
            if (Vector3.Distance(CacheTransform.position, targetCharacterEntity.CacheTransform.position) > gameInstance.conversationDistance)
            {
                gameManager.SendServerGameMessage(ConnectionId, GameMessage.Type.CharacterIsTooFar);
                return;
            }
            DealingCharacter = targetCharacterEntity;
            targetCharacterEntity.DealingCharacter = this;
            // Send receive dealing request to player
            DealingCharacter.RequestReceiveDealingRequest(ObjectId);
        }
 public bool RequestUnSummon(PackedUInt objectId)
 {
     CallNetFunction(NetFuncUnSummon, FunctionReceivers.Server, objectId);
     return(true);
 }
Esempio n. 18
0
        protected virtual void NetFuncBuild(short itemIndex, Vector3 position, Quaternion rotation, PackedUInt parentObjectId)
        {
            if (!CanDoActions() ||
                itemIndex >= NonEquipItems.Count)
            {
                return;
            }

            BuildingEntity buildingEntity;
            CharacterItem  nonEquipItem = NonEquipItems[itemIndex];

            if (!nonEquipItem.NotEmptySlot() ||
                nonEquipItem.GetBuildingItem() == null ||
                nonEquipItem.GetBuildingItem().buildingEntity == null ||
                !GameInstance.BuildingEntities.TryGetValue(nonEquipItem.GetBuildingItem().buildingEntity.DataId, out buildingEntity) ||
                !this.DecreaseItemsByIndex(itemIndex, 1))
            {
                return;
            }

            BuildingSaveData buildingSaveData = new BuildingSaveData();

            buildingSaveData.Id       = GenericUtils.GetUniqueId();
            buildingSaveData.ParentId = string.Empty;
            BuildingEntity parentBuildingEntity;

            if (TryGetEntityByObjectId(parentObjectId, out parentBuildingEntity))
            {
                buildingSaveData.ParentId = parentBuildingEntity.Id;
            }
            buildingSaveData.DataId      = buildingEntity.DataId;
            buildingSaveData.CurrentHp   = buildingEntity.maxHp;
            buildingSaveData.Position    = position;
            buildingSaveData.Rotation    = rotation;
            buildingSaveData.CreatorId   = Id;
            buildingSaveData.CreatorName = CharacterName;
            gameManager.CreateBuildingEntity(buildingSaveData, false);
        }
 public virtual void RequestUnSummon(PackedUInt objectId)
 {
     CallNetFunction(NetFuncUnSummon, FunctionReceivers.Server, objectId);
 }