Ejemplo n.º 1
0
        protected override void ServerUpdate(ServerUpdateData data)
        {
            var character    = data.GameObject;
            var publicState  = data.PublicState;
            var privateState = data.PrivateState;

            publicState.IsOnline = character.IsOnline;

            // update selected hotbar item
            SharedRefreshSelectedHotbarItem(character, privateState);

            if (publicState.IsDead)
            {
                // dead - stops processing character
                Server.Characters.SetMoveSpeed(character, 0);
                Server.Characters.SetVelocity(character, Vector2D.Zero);
                return;
            }

            // character is alive
            this.ServerRebuildFinalCacheIfNeeded(privateState, publicState);
            this.SharedApplyInput(character, privateState, publicState);

            // update weapon state (fires the weapon if needed)
            WeaponSystem.SharedUpdateCurrentWeapon(character, privateState.WeaponState, data.DeltaTime);
            // update current action state (if any)
            privateState.CurrentActionState?.SharedUpdate(data.DeltaTime);
            // update crafting queue
            CraftingMechanics.ServerUpdate(privateState.CraftingQueue, data.DeltaTime);
            // consumes/restores stamina
            CharacterStaminaSystem.SharedUpdate(character, publicState, privateState, (float)data.DeltaTime);
        }
Ejemplo n.º 2
0
        protected override void ServerUpdate(ServerUpdateData data)
        {
            var character    = data.GameObject;
            var publicState  = data.PublicState;
            var privateState = data.PrivateState;

            publicState.IsOnline = character.ServerIsOnline;

            // update selected hotbar item
            SharedRefreshSelectedHotbarItem(character, privateState);

            if (publicState.IsDead)
            {
                VehicleSystem.ServerCharacterExitCurrentVehicle(character, force: true);

                // dead - stops processing character
                var world = Server.World;
                world.SetDynamicObjectMoveSpeed(character, 0);
                world.SetDynamicObjectPhysicsMovement(character,
                                                      accelerationVector: Vector2D.Zero,
                                                      targetVelocity: 0);
                character.PhysicsBody.Friction = 100000;
                world.StopPhysicsBody(character.PhysicsBody);
                return;
            }

            // character is alive
            this.ServerRebuildFinalCacheIfNeeded(privateState, publicState);
            this.SharedApplyInput(character, privateState, publicState);

            // update weapon state (fires the weapon if needed)
            WeaponSystem.SharedUpdateCurrentWeapon(character, privateState.WeaponState, data.DeltaTime);
            // update current action state (if any)
            privateState.CurrentActionState?.SharedUpdate(data.DeltaTime);
            // update crafting queue
            CraftingMechanics.ServerUpdate(privateState.CraftingQueue, data.DeltaTime);
            // consumes/restores stamina
            CharacterStaminaSystem.SharedUpdate(character, publicState, privateState, data.DeltaTime);
        }
Ejemplo n.º 3
0
        private static void DropPlayerLoot(ICharacter character)
        {
            var containerEquipment = character.SharedGetPlayerContainerEquipment();
            var containerHand      = character.SharedGetPlayerContainerHand();
            var containerHotbar    = character.SharedGetPlayerContainerHotbar();
            var containerInventory = character.SharedGetPlayerContainerInventory();

            if (PveSystem.ServerIsPvE)
            {
                // don't drop player loot on death in PvE
                Api.Logger.Important("Player character is dead - reduce durability for the equipped items", character);

                // process items and drop loot
                ProcessContainerItemsOnDeathInPvE(isEquipmentContainer: true,
                                                  fromContainer: containerEquipment);

                ProcessContainerItemsOnDeathInPvE(isEquipmentContainer: false,
                                                  fromContainer: containerHand);

                ProcessContainerItemsOnDeathInPvE(isEquipmentContainer: false,
                                                  fromContainer: containerHotbar);

                ProcessContainerItemsOnDeathInPvE(isEquipmentContainer: false,
                                                  fromContainer: containerInventory);
                return;
            }

            Api.Logger.Important("Player character is dead - drop loot", character);

            CraftingMechanics.ServerCancelCraftingQueue(character);

            var characterContainersOccupiedSlotsCount = containerEquipment.OccupiedSlotsCount
                                                        + containerHand.OccupiedSlotsCount
                                                        + containerHotbar.OccupiedSlotsCount
                                                        + containerInventory.OccupiedSlotsCount;

            if (characterContainersOccupiedSlotsCount == 0)
            {
                Api.Logger.Important("No need to drop loot for dead character (no items to drop)", character);
                return;
            }

            var lootContainer = ObjectPlayerLootContainer.ServerTryCreateLootContainer(character);

            if (lootContainer is null)
            {
                Api.Logger.Error("Unable to drop loot for dead character", character);
                return;
            }

            // set slots count matching the total occupied slots count
            ServerItems.SetSlotsCount(
                lootContainer,
                (byte)characterContainersOccupiedSlotsCount);

            // process items and drop loot
            ProcessContainerItemsOnDeathInPvP(isEquipmentContainer: true,
                                              fromContainer: containerEquipment,
                                              toContainer: lootContainer);

            ProcessContainerItemsOnDeathInPvP(isEquipmentContainer: false,
                                              fromContainer: containerHand,
                                              toContainer: lootContainer);

            ProcessContainerItemsOnDeathInPvP(isEquipmentContainer: false,
                                              fromContainer: containerHotbar,
                                              toContainer: lootContainer);

            ProcessContainerItemsOnDeathInPvP(isEquipmentContainer: false,
                                              fromContainer: containerInventory,
                                              toContainer: lootContainer);

            if (lootContainer.OccupiedSlotsCount <= 0)
            {
                // nothing dropped, destroy the just spawned loot container
                ServerWorld.DestroyObject((IWorldObject)lootContainer.Owner);
                return;
            }

            // set exact slots count
            ServerItems.SetSlotsCount(
                lootContainer,
                (byte)lootContainer.OccupiedSlotsCount);

            SharedLootDropNotifyHelper.ServerOnLootDropped(lootContainer);
            // please note - no need to notify player about the dropped loot, it's automatically done by ClientDroppedItemsNotificationsManager
        }