public static void ServerDespawnDrone(IDynamicWorldObject objectDrone, bool isReturnedToPlayer)
        {
            var privateState = objectDrone.GetPrivateState <DronePrivateState>();
            var publicState  = objectDrone.GetPublicState <DronePublicState>();

            publicState.ResetTargetPosition();

            if (privateState.IsDespawned)
            {
                return;
            }

            var droneItem      = privateState.AssociatedItem;
            var protoItemDrone = (IProtoItemDrone)droneItem.ProtoItem;
            var characterOwner = privateState.CharacterOwner;
            var world          = Server.World;

            var protoDrone = protoItemDrone.ProtoDrone;

            protoDrone.ServerOnDroneDroppedOrReturned(objectDrone, characterOwner, isReturnedToPlayer);

            // recreate physics (as despawned drone doesn't have any physics)
            privateState.IsDespawned = true;
            world.StopPhysicsBody(objectDrone.PhysicsBody);
            objectDrone.ProtoWorldObject.SharedCreatePhysics(objectDrone);
            world.SetPosition(objectDrone,
                              ServerCharacterDeathMechanic.ServerGetGraveyardPosition().ToVector2D());

            privateState.CharacterOwner = null;
            ServerOnDroneControlRemoved(characterOwner, objectDrone);

            var currentDurability = (int)(objectDrone.GetPublicState <DronePublicState>().StructurePointsCurrent
                                          / protoItemDrone.DurabilityToStructurePointsConversionCoefficient);

            if (currentDurability <= 1)
            {
                currentDurability = 0;
            }

            var deltaDurabilility = (int)(ItemDurabilitySystem.SharedGetDurabilityValue(droneItem)
                                          - currentDurability);

            if (deltaDurabilility <= 0)
            {
                return;
            }

            ItemDurabilitySystem.ServerModifyDurability(droneItem,
                                                        -deltaDurabilility);

            if (droneItem.IsDestroyed)
            {
                // drone item degraded to 100%, notify the player
                ItemDurabilitySystem.Instance.CallClient(characterOwner,
                                                         _ => _.ClientRemote_ItemBroke(droneItem.ProtoItem));
            }
        }
Example #2
0
        protected override bool ServerIsCompleted(ICharacter character, PlayerTaskState state)
        {
            if (!character.ServerIsOnline ||
                character.TilePosition == ServerCharacterDeathMechanic.ServerGetGraveyardPosition())
            {
                return(false);
            }

            return(character.Tile.ProtoTile == this.ProtoTile);
        }
        public static void ServerPutIntoGarage(IDynamicWorldObject vehicle)
        {
            var position = ServerCharacterDeathMechanic.ServerGetGraveyardPosition().ToVector2D();

            var vehiclePrivateState = vehicle.GetPrivateState <VehiclePrivateState>();

            if (vehiclePrivateState.IsInGarage &&
                vehicle.Position == position)
            {
                // already in garage
                return;
            }

            var vehicleCurrentPilot = vehicle.GetPublicState <VehiclePublicState>().PilotCharacter;

            if (vehicleCurrentPilot != null)
            {
                VehicleSystem.ServerCharacterExitCurrentVehicle(vehicleCurrentPilot, force: true);
            }

            vehiclePrivateState.IsInGarage = true;

            Server.World.SetPosition(vehicle,
                                     position,
                                     writeToLog: false);

            VehicleSystem.ServerResetLastVehicleMapMark(vehiclePrivateState);

            vehicle.ProtoWorldObject.SharedCreatePhysics(vehicle);
            Logger.Important("Vehicle put into the garage: " + vehicle,
                             characterRelated: ServerRemoteContext.IsRemoteCall
                                                   ? ServerRemoteContext.Character
                                                   : null);

            if (ServerRemoteContext.IsRemoteCall)
            {
                // this action is done by player
                return;
            }

            // server put vehicle into garage - notify owners
            foreach (var owner in vehiclePrivateState.Owners)
            {
                var player = Server.Characters.GetPlayerCharacter(owner);
                if (player == null)
                {
                    continue;
                }

                var protoVehicle = (IProtoVehicle)vehicle.ProtoGameObject;
                Instance.CallClient(player, _ => _.ClientRemote_VehicleInGarage(protoVehicle));
            }
        }
Example #4
0
        protected override void ServerInitialize(ServerInitializeData data)
        {
            base.ServerInitialize(data);
            if (!data.IsFirstTimeInit)
            {
                return;
            }

            var item        = data.GameObject;
            var protoDrone  = LazyProtoDrone.Value;
            var objectDrone = Server.World.CreateDynamicWorldObject(
                protoDrone,
                ServerCharacterDeathMechanic.ServerGetGraveyardPosition().ToVector2D());

            protoDrone.ServerSetupAssociatedItem(objectDrone, item);
            data.PrivateState.WorldObjectDrone = objectDrone;
        }