예제 #1
0
        public void ServerWrite(IWriteMessage msg, Barotrauma.Networking.Client c, object[] extraData = null)
        {
            msg.Write(autoPilot);
            msg.Write(extraData.Length > 2 && extraData[2] is bool && (bool)extraData[2]);

            if (!autoPilot)
            {
                //no need to write steering info if autopilot is controlling
                msg.Write(steeringInput.X);
                msg.Write(steeringInput.Y);
                msg.Write(targetVelocity.X);
                msg.Write(targetVelocity.Y);
                msg.Write(steeringAdjustSpeed);
            }
            else
            {
                msg.Write(posToMaintain != null);
                if (posToMaintain != null)
                {
                    msg.Write(((Vector2)posToMaintain).X);
                    msg.Write(((Vector2)posToMaintain).Y);
                }
                else
                {
                    msg.Write(LevelStartSelected);
                }
            }
        }
예제 #2
0
        public void ServerWrite(Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c, object[] extraData = null)
        {
            msg.Write(autoPilot);

            if (!autoPilot)
            {
                //no need to write steering info if autopilot is controlling
                msg.Write(steeringInput.X);
                msg.Write(steeringInput.Y);
                msg.Write(targetVelocity.X);
                msg.Write(targetVelocity.Y);
                msg.Write(steeringAdjustSpeed);
            }
            else
            {
                msg.Write(posToMaintain != null);
                if (posToMaintain != null)
                {
                    msg.Write(((Vector2)posToMaintain).X);
                    msg.Write(((Vector2)posToMaintain).Y);
                }
                else
                {
                    msg.Write(LevelStartSelected);
                }
            }
        }
예제 #3
0
 private void AdjustKarma(IDamageable attacker, float amount)
 {
     if (GameMain.Server != null)
     {
         if (Submarine == null)
         {
             return;
         }
         if (attacker == null)
         {
             return;
         }
         if (attacker is Character)
         {
             Character attackerCharacter = attacker as Character;
             Barotrauma.Networking.Client attackerClient = GameMain.Server.ConnectedClients.Find(c => c.Character == attackerCharacter);
             if (attackerClient != null)
             {
                 if (attackerCharacter.TeamID == Submarine.TeamID)
                 {
                     attackerClient.Karma -= amount * 0.001f;
                 }
             }
         }
     }
 }
예제 #4
0
        public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c)
        {
            bool    autoPilot         = msg.ReadBoolean();
            Vector2 newTargetVelocity = targetVelocity;
            bool    maintainPos       = false;
            Vector2?newPosToMaintain  = null;
            bool    headingToStart    = false;

            if (autoPilot)
            {
                maintainPos = msg.ReadBoolean();
                if (maintainPos)
                {
                    newPosToMaintain = new Vector2(
                        msg.ReadFloat(),
                        msg.ReadFloat());
                }
                else
                {
                    headingToStart = msg.ReadBoolean();
                }
            }
            else
            {
                newTargetVelocity = new Vector2(msg.ReadFloat(), msg.ReadFloat());
            }

            if (!item.CanClientAccess(c))
            {
                return;
            }

            AutoPilot = autoPilot;

            if (!AutoPilot)
            {
                targetVelocity = newTargetVelocity;
            }
            else
            {
                MaintainPos   = newPosToMaintain != null;
                posToMaintain = newPosToMaintain;

                if (posToMaintain == null)
                {
                    LevelStartSelected = headingToStart;
                    LevelEndSelected   = !headingToStart;
                    UpdatePath();
                }
                else
                {
                    LevelStartSelected = false;
                    LevelEndSelected   = false;
                }
            }

            //notify all clients of the changed state
            unsentChanges = true;
        }
예제 #5
0
        public override bool Use(float deltaTime, Character character = null)
        {
            if (!attachable || item.body == null)
            {
                return(true);
            }
            if (character != null)
            {
                if (!character.IsKeyDown(InputType.Aim))
                {
                    return(false);
                }
                if (character.CurrentHull == null)
                {
                    return(false);
                }
                if (GameMain.Server != null)
                {
                    item.CreateServerEvent(this);
                    GameServer.Log(character.LogName + " attached " + item.Name + " to a wall", ServerLog.MessageType.ItemInteraction);

                    //Detonator attachment check
                    for (int y = 0; y < NilMod.NilModGriefWatcher.GWListDetonators.Count; y++)
                    {
                        if (NilMod.NilModGriefWatcher.GWListDetonators[y] == item.Name)
                        {
                            Barotrauma.Networking.Client warnedclient = GameMain.Server.ConnectedClients.Find(c => c.Character == character);

                            if (item.ContainedItems == null || item.ContainedItems.All(it => it == null))
                            {
                                NilMod.NilModGriefWatcher.SendWarning(character.LogName
                                                                      + " attached " + item.Name
                                                                      + " to a wall", warnedclient);
                            }
                            else
                            {
                                NilMod.NilModGriefWatcher.SendWarning(character.LogName
                                                                      + " attached " + item.Name
                                                                      + " (" + string.Join(", ", System.Array.FindAll(item.ContainedItems, it => it != null).Select(it => it.Name))
                                                                      + ")"
                                                                      + " to a wall", warnedclient);
                            }
                        }
                    }
                }
                item.Drop();
            }

            AttachToWall();
            if (attached && character != null)
            {
                attachedby = character;
            }

            return(true);
        }
예제 #6
0
        public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c)
        {
            bool isActive = msg.ReadBoolean();

            if (!item.CanClientAccess(c))
            {
                return;
            }

            IsActive = isActive;
            isActiveTickBox.Selected = IsActive;

            item.CreateServerEvent(this);
        }
예제 #7
0

        
예제 #8
0
        public static void ServerRead(IReadMessage msg, Client c)
        {
            c.KickAFKTimer = 0.0f;

            UInt16          ID   = msg.ReadUInt16();
            ChatMessageType type = (ChatMessageType)msg.ReadByte();
            string          txt;

            Character        orderTargetCharacter = null;
            Entity           orderTargetEntity    = null;
            OrderChatMessage orderMsg             = null;
            OrderTarget      orderTargetPosition  = null;

            Order.OrderTargetType orderTargetType = Order.OrderTargetType.Entity;
            int?wallSectionIndex = null;

            if (type == ChatMessageType.Order)
            {
                int orderIndex = msg.ReadByte();
                orderTargetCharacter = Entity.FindEntityByID(msg.ReadUInt16()) as Character;
                orderTargetEntity    = Entity.FindEntityByID(msg.ReadUInt16()) as Entity;
                int orderOptionIndex = msg.ReadByte();
                orderTargetType = (Order.OrderTargetType)msg.ReadByte();
                if (msg.ReadBoolean())
                {
                    var x    = msg.ReadSingle();
                    var y    = msg.ReadSingle();
                    var hull = Entity.FindEntityByID(msg.ReadUInt16()) as Hull;
                    orderTargetPosition = new OrderTarget(new Vector2(x, y), hull, true);
                }
                else if (orderTargetType == Order.OrderTargetType.WallSection)
                {
                    wallSectionIndex = msg.ReadByte();
                }

                if (orderIndex < 0 || orderIndex >= Order.PrefabList.Count)
                {
                    DebugConsole.ThrowError($"Invalid order message from client \"{c.Name}\" - order index out of bounds ({orderIndex}, {orderOptionIndex}).");
                    if (NetIdUtils.IdMoreRecent(ID, c.LastSentChatMsgID))
                    {
                        c.LastSentChatMsgID = ID;
                    }
                    return;
                }

                Order  orderPrefab = Order.PrefabList[orderIndex];
                string orderOption = orderOptionIndex < 0 || orderOptionIndex >= orderPrefab.Options.Length ? "" : orderPrefab.Options[orderOptionIndex];
                orderMsg = new OrderChatMessage(orderPrefab, orderOption, orderTargetPosition ?? orderTargetEntity as ISpatialEntity, orderTargetCharacter, c.Character)
                {
                    WallSectionIndex = wallSectionIndex
                };
                txt = orderMsg.Text;
            }
            else
            {
                txt = msg.ReadString() ?? "";
            }

            if (!NetIdUtils.IdMoreRecent(ID, c.LastSentChatMsgID))
            {
                return;
            }

            c.LastSentChatMsgID = ID;

            if (txt.Length > MaxLength)
            {
                txt = txt.Substring(0, MaxLength);
            }

            c.LastSentChatMessages.Add(txt);
            if (c.LastSentChatMessages.Count > 10)
            {
                c.LastSentChatMessages.RemoveRange(0, c.LastSentChatMessages.Count - 10);
            }

            float similarity = 0.0f;

            for (int i = 0; i < c.LastSentChatMessages.Count; i++)
            {
                float closeFactor = 1.0f / (c.LastSentChatMessages.Count - i);

                if (string.IsNullOrEmpty(txt))
                {
                    similarity += closeFactor;
                }
                else
                {
                    int levenshteinDist = ToolBox.LevenshteinDistance(txt, c.LastSentChatMessages[i]);
                    similarity += Math.Max((txt.Length - levenshteinDist) / (float)txt.Length * closeFactor, 0.0f);
                }
            }
            //order/report messages can be sent a little faster than normal messages without triggering the spam filter
            if (orderMsg != null)
            {
                similarity *= 0.25f;
            }

            bool isOwner = GameMain.Server.OwnerConnection != null && c.Connection == GameMain.Server.OwnerConnection;

            if (similarity + c.ChatSpamSpeed > 5.0f && !isOwner)
            {
                GameMain.Server.KarmaManager.OnSpamFilterTriggered(c);

                c.ChatSpamCount++;
                if (c.ChatSpamCount > 3)
                {
                    //kick for spamming too much
                    GameMain.Server.KickClient(c, TextManager.Get("SpamFilterKicked"));
                }
                else
                {
                    ChatMessage denyMsg = Create("", TextManager.Get("SpamFilterBlocked"), ChatMessageType.Server, null);
                    c.ChatSpamTimer = 10.0f;
                    GameMain.Server.SendDirectChatMessage(denyMsg, c);
                }
                return;
            }

            c.ChatSpamSpeed += similarity + 0.5f;

            if (c.ChatSpamTimer > 0.0f && !isOwner)
            {
                ChatMessage denyMsg = Create("", TextManager.Get("SpamFilterBlocked"), ChatMessageType.Server, null);
                c.ChatSpamTimer = 10.0f;
                GameMain.Server.SendDirectChatMessage(denyMsg, c);
                return;
            }

            if (type == ChatMessageType.Order)
            {
                if (c.Character == null || c.Character.SpeechImpediment >= 100.0f || c.Character.IsDead)
                {
                    return;
                }
                Order order = null;
                if (orderMsg.Order.IsReport)
                {
                    HumanAIController.ReportProblem(orderMsg.Sender, orderMsg.Order);
                }
                else if (orderTargetCharacter != null && !orderMsg.Order.TargetAllCharacters)
                {
                    switch (orderTargetType)
                    {
                    case Order.OrderTargetType.Entity:
                        order = new Order(orderMsg.Order.Prefab, orderTargetEntity, orderMsg.Order.Prefab?.GetTargetItemComponent(orderTargetEntity as Item), orderGiver: orderMsg.Sender);
                        break;

                    case Order.OrderTargetType.Position:
                        order = new Order(orderMsg.Order.Prefab, orderTargetPosition, orderGiver: orderMsg.Sender);
                        break;
                    }
                    if (order != null)
                    {
                        orderTargetCharacter.SetOrder(order, orderMsg.OrderOption, orderMsg.Sender);
                    }
                }
                else if (orderMsg.Order.IsIgnoreOrder)
                {
                    switch (orderTargetType)
                    {
                    case Order.OrderTargetType.Entity:
                        (orderTargetEntity as MapEntity)?.SetIgnoreByAI(orderMsg.Order.Identifier == "ignorethis");
                        break;

                    case Order.OrderTargetType.WallSection:
                        if (!wallSectionIndex.HasValue)
                        {
                            break;
                        }
                        (orderTargetEntity as Structure)?.GetSection(wallSectionIndex.Value)?.SetIgnoreByAI(orderMsg.Order.Identifier == "ignorethis");
                        break;
                    }
                }
                GameMain.Server.SendOrderChatMessage(orderMsg);
            }
            else
            {
                GameMain.Server.SendChatMessage(txt, null, c);
            }
        }
예제 #9
0
        public void ServerRead(ClientNetObject type, NetBuffer msg, Barotrauma.Networking.Client c)
        {
            List <Item> prevItems = new List <Item>(Items);

            ushort[] newItemIDs = new ushort[capacity];

            for (int i = 0; i < capacity; i++)
            {
                newItemIDs[i] = msg.ReadUInt16();
            }

            if (c == null || c.Character == null || !c.Character.CanAccessInventory(this))
            {
                return;
            }

            for (int i = 0; i < capacity; i++)
            {
                if (newItemIDs[i] == 0)
                {
                    if (Items[i] != null)
                    {
                        Items[i].Drop(c.Character);
                    }
                    System.Diagnostics.Debug.Assert(Items[i] == null);
                }
                else
                {
                    var item = Entity.FindEntityByID(newItemIDs[i]) as Item;
                    if (item == null || item == Items[i])
                    {
                        continue;
                    }

                    if (GameMain.Server != null)
                    {
                        if (!item.CanClientAccess(c))
                        {
                            continue;
                        }
                    }
                    TryPutItem(item, i, true, false);
                }
            }

            GameMain.Server.CreateEntityEvent(Owner as IServerSerializable, new object[] { NetEntityEvent.Type.InventoryState });

            foreach (Item item in Items.Distinct())
            {
                if (item == null)
                {
                    continue;
                }
                if (!prevItems.Contains(item))
                {
                    if (Owner == c.Character)
                    {
                        GameServer.Log(c.Character + " picked up " + item.Name, ServerLog.MessageType.Inventory);
                    }
                    else
                    {
                        GameServer.Log(c.Character + " placed " + item.Name + " in " + Owner, ServerLog.MessageType.Inventory);
                    }
                }
            }
            foreach (Item item in prevItems.Distinct())
            {
                if (item == null)
                {
                    continue;
                }
                if (!Items.Contains(item))
                {
                    if (Owner == c.Character)
                    {
                        GameServer.Log(c.Character + " dropped " + item.Name, ServerLog.MessageType.Inventory);
                    }
                    else
                    {
                        GameServer.Log(c.Character + " removed " + item.Name + " from " + Owner, ServerLog.MessageType.Inventory);
                    }
                }
            }
        }
예제 #10
0
        public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c)
        {
            bool    autoPilot            = msg.ReadBoolean();
            bool    dockingButtonClicked = msg.ReadBoolean();
            Vector2 newSteeringInput     = targetVelocity;
            bool    maintainPos          = false;
            Vector2?newPosToMaintain     = null;
            bool    headingToStart       = false;

            if (autoPilot)
            {
                maintainPos = msg.ReadBoolean();
                if (maintainPos)
                {
                    newPosToMaintain = new Vector2(
                        msg.ReadFloat(),
                        msg.ReadFloat());
                }
                else
                {
                    headingToStart = msg.ReadBoolean();
                }
            }
            else
            {
                newSteeringInput = new Vector2(msg.ReadFloat(), msg.ReadFloat());
            }

            if (!item.CanClientAccess(c))
            {
                return;
            }

            user      = c.Character;
            AutoPilot = autoPilot;

            if (dockingButtonClicked)
            {
                item.SendSignal(0, "1", "toggle_docking", sender: Character.Controlled);
            }

            if (!AutoPilot)
            {
                steeringInput       = newSteeringInput;
                steeringAdjustSpeed = MathHelper.Lerp(0.2f, 1.0f, c.Character.GetSkillLevel("helm") / 100.0f);
            }
            else
            {
                MaintainPos   = newPosToMaintain != null;
                posToMaintain = newPosToMaintain;

                if (posToMaintain == null)
                {
                    LevelStartSelected = headingToStart;
                    LevelEndSelected   = !headingToStart;
                    UpdatePath();
                }
                else
                {
                    LevelStartSelected = false;
                    LevelEndSelected   = false;
                }
            }

            //notify all clients of the changed state
            unsentChanges = true;
        }
예제 #11
0
 public void ServerWrite(Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c, object[] extraData = null)
 {
     msg.Write(isOpen);
     msg.WriteRangedSingle(stuck, 0.0f, 100.0f, 8);
 }
예제 #12
0
        /// <summary>
        /// If there is room, puts the item in the inventory and returns true, otherwise returns false
        /// </summary>
        public override bool TryPutItem(Item item, Character user, List <InvSlotType> allowedSlots = null, bool createNetworkEvent = true)
        {
            if (allowedSlots == null || !allowedSlots.Any())
            {
                return(false);
            }

            for (int i = 0; i < capacity; i++)
            {
                //already in the inventory and in a suitable slot
                if (Items[i] == item && allowedSlots.Any(a => a.HasFlag(limbSlots[i])))
                {
                    return(true);
                }
            }

            //try to place the item in LimBlot.Any slot if that's allowed
            if (allowedSlots.Contains(InvSlotType.Any))
            {
                for (int i = 0; i < capacity; i++)
                {
                    if (Items[i] != null || limbSlots[i] != InvSlotType.Any)
                    {
                        continue;
                    }

                    PutItem(item, i, user, true, createNetworkEvent);
                    item.Unequip(character);
                    return(true);
                }
            }

            bool placed = false;

            foreach (InvSlotType allowedSlot in allowedSlots)
            {
                //check if all the required slots are free
                bool free = true;
                for (int i = 0; i < capacity; i++)
                {
                    if (allowedSlot.HasFlag(limbSlots[i]) && Items[i] != null && Items[i] != item)
                    {
                        free = false;
#if CLIENT
                        if (slots != null)
                        {
                            slots[i].ShowBorderHighlight(Color.Red, 0.1f, 0.9f);
                        }
#endif
                    }
                }

                if (!free)
                {
                    continue;
                }

                for (int i = 0; i < capacity; i++)
                {
                    if (allowedSlot.HasFlag(limbSlots[i]) && Items[i] == null)
                    {
                        PutItem(item, i, user, !placed, createNetworkEvent);
                        item.Equip(character);
                        placed = true;
                    }
                }

                if (placed)
                {
                    if (GameMain.NilMod.EnableGriefWatcher && GameMain.Server != null && user != null && user != character && user.TeamID == character.TeamID)
                    {
                        if (GameMain.Server.TraitorManager != null && !GameMain.Server.TraitorManager.IsTraitor(character))
                        {
                            Barotrauma.Networking.Client warnedclient = GameMain.Server.ConnectedClients.Find(c => c.Character == user);

                            //Code for mask item checks
                            if (item.ContainedItems != null &&
                                item.ContainedItems.Count() > 0 &&
                                !character.IsDead &&
                                ((GameMain.Server.ConnectedClients.Find(c => c.Character == character) != null) ||
                                 character.AIController == null) && user.TeamID == character.TeamID)
                            {
                                if (IsInLimbSlot(item, InvSlotType.Face) ||
                                    IsInLimbSlot(item, InvSlotType.Head) ||
                                    IsInLimbSlot(item, InvSlotType.Torso) ||
                                    IsInLimbSlot(item, InvSlotType.Legs))
                                {
                                    //Mask item checks
                                    for (int y = 0; y < NilMod.NilModGriefWatcher.GWListMaskItems.Count; y++)
                                    {
                                        if (NilMod.NilModGriefWatcher.GWListMaskItems[y] == item.Name)
                                        {
                                            for (int z = 0; z < NilMod.NilModGriefWatcher.GWListMaskHazardous.Count; z++)
                                            {
                                                if (Array.FindAll(item.ContainedItems, i => i != null).Select(i => i.Name).Contains(NilMod.NilModGriefWatcher.GWListMaskHazardous[z]))
                                                {
                                                    NilMod.NilModGriefWatcher.SendWarning(user.LogName
                                                                                          + " placed lethal wearable " + item.Name
                                                                                          + " (" + string.Join(", ", Array.FindAll(item.ContainedItems, i => i != null).Select(i => i.Name)) + ")"
                                                                                          + " on " + character.LogName, warnedclient);
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            if (!character.IsDead &&
                                ((GameMain.Server.ConnectedClients.Find(c => c.Character == character) != null) ||
                                 character.AIController == null) && user.TeamID == character.TeamID)
                            {
                                //Incase a mod decides to have straightjackets or something
                                if (IsInLimbSlot(item, InvSlotType.RightHand) ||
                                    IsInLimbSlot(item, InvSlotType.LeftHand) ||
                                    IsInLimbSlot(item, InvSlotType.Face) ||
                                    IsInLimbSlot(item, InvSlotType.Head) ||
                                    IsInLimbSlot(item, InvSlotType.Torso) ||
                                    IsInLimbSlot(item, InvSlotType.Legs))
                                {
                                    //Handcuff checks
                                    for (int y = 0; y < NilMod.NilModGriefWatcher.GWListHandcuffs.Count; y++)
                                    {
                                        if (NilMod.NilModGriefWatcher.GWListHandcuffs[y] == item.Name)
                                        {
                                            NilMod.NilModGriefWatcher.SendWarning(user.LogName
                                                                                  + " placed " + item.Name
                                                                                  + " on " + character.LogName, warnedclient);
                                        }
                                    }
                                }
                            }
                        }
                    }


                    return(true);
                }
            }


            return(placed);
        }
예제 #13
0
        public override bool Use(float deltaTime, Character character = null)
        {
            if (GameMain.Client != null)
            {
                return(false);
            }

            if (reload > 0.0f)
            {
                return(false);
            }

            var projectiles = GetLoadedProjectiles(true);

            if (projectiles.Count == 0)
            {
                return(false);
            }

            if (GetAvailablePower() < powerConsumption)
            {
                return(false);
            }

            var batteries = item.GetConnectedComponents <PowerContainer>();

            float availablePower = 0.0f;

            foreach (PowerContainer battery in batteries)
            {
                float batteryPower = Math.Min(battery.Charge * 3600.0f, battery.MaxOutPut);
                float takePower    = Math.Min(powerConsumption - availablePower, batteryPower);

                battery.Charge -= takePower / 3600.0f;

                if (GameMain.Server != null)
                {
                    battery.Item.CreateServerEvent(battery);
                }
            }

            Launch(projectiles[0].Item, character);

            if (character != null)
            {
                string msg = character.LogName + " launched " + item.Name + " (projectile: " + projectiles[0].Item.Name;
                if (projectiles[0].Item.ContainedItems == null || projectiles[0].Item.ContainedItems.All(i => i == null))
                {
                    msg += ")";
                }
                else
                {
                    msg += ", contained items: " + string.Join(", ", Array.FindAll(projectiles[0].Item.ContainedItems, i => i != null).Select(i => i.Name)) + ")";
                }
                GameServer.Log(msg, ServerLog.MessageType.Attack);

                if (GameMain.Server != null && GameMain.NilMod.EnableGriefWatcher)
                {
                    for (int y = 0; y < NilMod.NilModGriefWatcher.GWListRailgunLaunch.Count; y++)
                    {
                        if (NilMod.NilModGriefWatcher.GWListRailgunLaunch[y] == projectiles[0].Item.Name)
                        {
                            Barotrauma.Networking.Client warnedclient = GameMain.Server.ConnectedClients.Find(c => c.Character == character);

                            if (item.ContainedItems == null || item.ContainedItems.All(it => it == null))
                            {
                                NilMod.NilModGriefWatcher.SendWarning(character.LogName
                                                                      + " launched " + projectiles[0].Item.Name
                                                                      + " from " + item.Name, warnedclient);
                            }
                            else
                            {
                                NilMod.NilModGriefWatcher.SendWarning(character.LogName
                                                                      + " launched " + projectiles[0].Item.Name
                                                                      + " (" + string.Join(", ", System.Array.FindAll(item.ContainedItems, it => it != null).Select(it => it.Name))
                                                                      + ")"
                                                                      + " from " + item.Name, warnedclient);
                            }
                        }
                    }
                }
            }

            return(true);
        }
예제 #14
0
        public override void Update(float deltaTime, Camera cam)
        {
            if (!item.body.Enabled)
            {
                return;
            }
            if (picker == null || picker.Removed || !picker.HasSelectedItem(item))
            {
                IsActive = false;
                return;
            }

            if (picker.IsKeyDown(InputType.Aim) && picker.IsKeyHit(InputType.Use))
            {
                throwing = true;
            }

            if (!picker.IsKeyDown(InputType.Aim) && !throwing)
            {
                throwPos = 0.0f;
            }

            ApplyStatusEffects(ActionType.OnActive, deltaTime, picker);

            if (item.body.Dir != picker.AnimController.Dir)
            {
                Flip(item);
            }

            AnimController ac = picker.AnimController;

            item.Submarine = picker.Submarine;

            if (!throwing)
            {
                if (picker.IsKeyDown(InputType.Aim))
                {
                    throwPos = (float)System.Math.Min(throwPos + deltaTime * 5.0f, MathHelper.Pi * 0.7f);

                    ac.HoldItem(deltaTime, item, handlePos, new Vector2(0.6f, -0.0f), new Vector2(-0.3f, 0.2f), false, throwPos);
                }
                else
                {
                    ac.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, false, holdAngle);
                }
            }
            else
            {
                throwPos -= deltaTime * 15.0f;

                ac.HoldItem(deltaTime, item, handlePos, new Vector2(0.6f, 0.0f), new Vector2(-0.3f, 0.2f), false, throwPos);

                if (throwPos < -0.0)
                {
                    Vector2 throwVector = Vector2.Normalize(picker.CursorWorldPosition - picker.WorldPosition);
                    //throw upwards if cursor is at the position of the character
                    if (!MathUtils.IsValid(throwVector))
                    {
                        throwVector = Vector2.UnitY;
                    }

                    GameServer.Log(picker.LogName + " threw " + item.Name, ServerLog.MessageType.ItemInteraction);

                    if (GameMain.NilMod.EnableGriefWatcher)
                    {
                        //Grief watch throw checks
                        for (int y = 0; y < NilMod.NilModGriefWatcher.GWListThrown.Count; y++)
                        {
                            if (NilMod.NilModGriefWatcher.GWListThrown[y] == Item.Name)
                            {
                                Barotrauma.Networking.Client warnedclient = GameMain.Server.ConnectedClients.Find(c => c.Character == picker);

                                if (item.ContainedItems == null || item.ContainedItems.All(it => it == null))
                                {
                                    NilMod.NilModGriefWatcher.SendWarning(picker.LogName
                                                                          + " threw dangerous item " + Item.Name, warnedclient);
                                }
                                else
                                {
                                    NilMod.NilModGriefWatcher.SendWarning(picker.LogName
                                                                          + " threw dangerous item "
                                                                          + Item.Name
                                                                          + " (" + string.Join(", ", System.Array.FindAll(item.ContainedItems, it => it != null).Select(it => it.Name))
                                                                          + ")", warnedclient);
                                }
                            }
                        }
                    }

                    item.Drop();
                    item.body.ApplyLinearImpulse(throwVector * throwForce * item.body.Mass * 3.0f);

                    ac.GetLimb(LimbType.Head).body.ApplyLinearImpulse(throwVector * 10.0f);
                    ac.GetLimb(LimbType.Torso).body.ApplyLinearImpulse(throwVector * 10.0f);

                    Limb rightHand = ac.GetLimb(LimbType.RightHand);
                    item.body.AngularVelocity = rightHand.body.AngularVelocity;
                    throwDone = true;
                    ApplyStatusEffects(ActionType.OnSecondaryUse, deltaTime, picker); //Stun grenades, flares, etc. all have their throw-related things handled in "onSecondaryUse"
                    throwing = false;
                }
            }
        }
예제 #15
0
 public void ServerWrite(Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c, object[] extraData = null)
 {
     msg.Write(IsActive);
 }
예제 #16
0
        public override bool TryPutItem(Item item, int i, bool allowSwapping, bool allowCombine, Character user, bool createNetworkEvent = true)
        {
            bool wasPut = base.TryPutItem(item, i, allowSwapping, allowCombine, user, createNetworkEvent);

            if (wasPut)
            {
                if (GameMain.NilMod.EnableGriefWatcher && GameMain.Server != null && user != null)
                {
                    Barotrauma.Networking.Client warnedclient = GameMain.Server.ConnectedClients.Find(c => c.Character == user);
                    if (warnedclient != null)
                    {
                        Item ownerasitem = Owner as Item;

                        //Detonator + Explosives checks
                        for (int y = 0; y < NilMod.NilModGriefWatcher.GWListDetonators.Count; y++)
                        {
                            if (NilMod.NilModGriefWatcher.GWListDetonators[y] == ownerasitem.Name)
                            {
                                for (int z = 0; z < NilMod.NilModGriefWatcher.GWListExplosives.Count; z++)
                                {
                                    if (NilMod.NilModGriefWatcher.GWListExplosives[z] == item.Name)
                                    {
                                        NilMod.NilModGriefWatcher.SendWarning(user.LogName
                                                                              + " placed explosive " + item.Name
                                                                              + " into " + ownerasitem.Name, warnedclient);
                                    }
                                }
                            }
                        }

                        //Railgun Ammo Loading checks
                        for (int y = 0; y < NilMod.NilModGriefWatcher.GWListRailgunRacks.Count; y++)
                        {
                            if (NilMod.NilModGriefWatcher.GWListRailgunRacks[y] == ownerasitem.Name)
                            {
                                for (int z = 0; z < NilMod.NilModGriefWatcher.GWListRailgunAmmo.Count; z++)
                                {
                                    if (NilMod.NilModGriefWatcher.GWListRailgunAmmo[z] == item.Name)
                                    {
                                        if (item.ContainedItems == null || item.ContainedItems.All(it => it == null))
                                        {
                                            NilMod.NilModGriefWatcher.SendWarning(user.LogName
                                                                                  + " Loaded " + item.Name
                                                                                  + " into " + ownerasitem.Name, warnedclient);
                                        }
                                        else
                                        {
                                            NilMod.NilModGriefWatcher.SendWarning(user.LogName
                                                                                  + " Loaded " + item.Name
                                                                                  + " into " + ownerasitem.Name
                                                                                  + " (" + string.Join(", ", System.Array.FindAll(item.ContainedItems, it => it != null).Select(it => it.Name))
                                                                                  + ")", warnedclient);
                                        }
                                    }
                                }
                            }
                        }
                        //Syringe Chemical checks
                        for (int y = 0; y < NilMod.NilModGriefWatcher.GWListSyringes.Count; y++)
                        {
                            if (NilMod.NilModGriefWatcher.GWListSyringes[y] == ownerasitem.Name)
                            {
                                for (int z = 0; z < NilMod.NilModGriefWatcher.GWListSyringechems.Count; z++)
                                {
                                    if (NilMod.NilModGriefWatcher.GWListSyringechems[z] == item.Name)
                                    {
                                        NilMod.NilModGriefWatcher.SendWarning(user.LogName
                                                                              + " placed dangerous chemical "
                                                                              + item.Name + " into "
                                                                              + ownerasitem.Name, warnedclient);
                                    }
                                }
                            }
                        }

                        //Ranged weapon ammo checks
                        for (int y = 0; y < NilMod.NilModGriefWatcher.GWListRanged.Count; y++)
                        {
                            if (NilMod.NilModGriefWatcher.GWListRanged[y] == ownerasitem.Name)
                            {
                                for (int z = 0; z < NilMod.NilModGriefWatcher.GWListRangedAmmo.Count; z++)
                                {
                                    if (NilMod.NilModGriefWatcher.GWListRangedAmmo[z] == item.Name)
                                    {
                                        if (item.ContainedItems == null || item.ContainedItems.All(it => it == null))
                                        {
                                            NilMod.NilModGriefWatcher.SendWarning(user.LogName
                                                                                  + " Loaded weapon " + ownerasitem.Name
                                                                                  + " with " + item.Name, warnedclient);
                                        }
                                        else
                                        {
                                            NilMod.NilModGriefWatcher.SendWarning(user.LogName
                                                                                  + " Loaded weapon " + ownerasitem.Name
                                                                                  + " with " + item.Name
                                                                                  + " (" + string.Join(", ", System.Array.FindAll(item.ContainedItems, it => it != null).Select(it => it.Name))
                                                                                  + ")", warnedclient);
                                        }
                                    }
                                }
                            }
                        }

                        //This is a characters or other characters inventory and the item is inside it
                        if (ownerasitem.ParentInventory != null && ownerasitem.ParentInventory is CharacterInventory)
                        {
                            CharacterInventory characterinventory = ownerasitem.ParentInventory as CharacterInventory;

                            //Mask item checks
                            if (!characterinventory.character.IsDead &&
                                ((GameMain.Server.ConnectedClients.Find(c => c.Character == characterinventory.character) != null) ||
                                 characterinventory.character.AIController == null))
                            {
                                //This is a currently worn item
                                if (characterinventory.IsInLimbSlot(ownerasitem, InvSlotType.Face) ||
                                    characterinventory.IsInLimbSlot(ownerasitem, InvSlotType.Head) ||
                                    characterinventory.IsInLimbSlot(ownerasitem, InvSlotType.Torso) ||
                                    characterinventory.IsInLimbSlot(ownerasitem, InvSlotType.Legs))
                                {
                                    for (int y = 0; y < NilMod.NilModGriefWatcher.GWListMaskItems.Count; y++)
                                    {
                                        if (NilMod.NilModGriefWatcher.GWListMaskItems[y] == ownerasitem.Name)
                                        {
                                            for (int z = 0; z < NilMod.NilModGriefWatcher.GWListMaskHazardous.Count; z++)
                                            {
                                                if (Array.FindAll(ownerasitem.ContainedItems, it => it != null).Select(it => it.Name).Contains(NilMod.NilModGriefWatcher.GWListMaskHazardous[z]))
                                                {
                                                    NilMod.NilModGriefWatcher.SendWarning(user.LogName
                                                                                          + " placed lethal wearable " + ownerasitem.Name
                                                                                          + " (" + string.Join(", ", Array.FindAll(ownerasitem.ContainedItems, it => it != null).Select(it => it.Name)) + ")"
                                                                                          + " on " + characterinventory.character.LogName, warnedclient);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                foreach (Character c in Character.CharacterList)
                {
                    if (!c.HasSelectedItem(item))
                    {
                        continue;
                    }

                    item.Unequip(c);
                    break;
                }

                container.IsActive = true;
                container.OnItemContained(item);
            }

            return(wasPut);
        }
예제 #17
0
        public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c)
        {
            bool    autoPilot         = msg.ReadBoolean();
            Vector2 newTargetVelocity = targetVelocity;
            bool    maintainPos       = false;
            Vector2?newPosToMaintain  = null;
            bool    headingToStart    = false;

            if (autoPilot)
            {
                maintainPos = msg.ReadBoolean();
                if (maintainPos)
                {
                    newPosToMaintain = new Vector2(
                        msg.ReadFloat(),
                        msg.ReadFloat());
                }
                else
                {
                    headingToStart = msg.ReadBoolean();
                }
            }
            else
            {
                newTargetVelocity = new Vector2(msg.ReadFloat(), msg.ReadFloat());
            }

            if (lastuser == null)
            {
                lastuser = c.Character;
            }

            if (!item.CanClientAccess(c))
            {
                return;
            }

            if (lastuser != c.Character)
            {
                if (!CoroutineManager.IsCoroutineRunning("warnislocked_" + item.ID + "_" + c.Character.ID))
                {
                    CoroutineManager.StartCoroutine(Warnislocked(c, item), "warnislocked_" + item.ID + "_" + c.Character.ID);
                }
                return;
            }

            AutoPilot = autoPilot;

            if (!AutoPilot)
            {
                targetVelocity = newTargetVelocity;
            }
            else
            {
                MaintainPos   = newPosToMaintain != null;
                posToMaintain = newPosToMaintain;

                if (posToMaintain == null)
                {
                    LevelStartSelected = headingToStart;
                    LevelEndSelected   = !headingToStart;
                    UpdatePath();
                }
                else
                {
                    LevelStartSelected = false;
                    LevelEndSelected   = false;
                }
            }

            //notify all clients of the changed state
            unsentChanges = true;
        }
예제 #18
0
        public void ServerRead(ClientNetObject type, IReadMessage msg, Barotrauma.Networking.Client c)
        {
            bool    autoPilot            = msg.ReadBoolean();
            bool    dockingButtonClicked = msg.ReadBoolean();
            Vector2 newSteeringInput     = targetVelocity;
            Vector2?newPosToMaintain     = null;
            bool    headingToStart       = false;

            if (autoPilot)
            {
                bool maintainPos = msg.ReadBoolean();
                if (maintainPos)
                {
                    newPosToMaintain = new Vector2(
                        msg.ReadSingle(),
                        msg.ReadSingle());
                }
                else
                {
                    headingToStart = msg.ReadBoolean();
                }
            }
            else
            {
                newSteeringInput = new Vector2(msg.ReadSingle(), msg.ReadSingle());
            }

            if (!item.CanClientAccess(c))
            {
                return;
            }

            user      = c.Character;
            AutoPilot = autoPilot;

            if (dockingButtonClicked)
            {
                item.SendSignal("1", "toggle_docking");
                GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.ComponentState, item.GetComponentIndex(this), true });
            }

            if (!AutoPilot)
            {
                steeringInput       = newSteeringInput;
                steeringAdjustSpeed = MathHelper.Lerp(0.2f, 1.0f, c.Character.GetSkillLevel("helm") / 100.0f);
            }
            else
            {
                MaintainPos   = newPosToMaintain != null;
                posToMaintain = newPosToMaintain;

                if (posToMaintain == null)
                {
                    LevelStartSelected = headingToStart;
                    LevelEndSelected   = !headingToStart;
                    UpdatePath();
                }
                else
                {
                    LevelStartSelected = false;
                    LevelEndSelected   = false;
                }
            }

            //notify all clients of the changed state
            unsentChanges = true;
        }
예제 #19
0
        protected void Apply(float deltaTime, Entity entity, List <ISerializableEntity> targets, List <int> cancelledEffects = null, Character causecharacter = null, string identifier = "")
        {
#if CLIENT
            if (sound != null)
            {
                if (loopSound)
                {
                    if (!Sounds.SoundManager.IsPlaying(sound))
                    {
                        sound.Play(entity.WorldPosition);
                    }
                    else
                    {
                        sound.UpdatePosition(entity.WorldPosition);
                    }
                }
                else
                {
                    sound.Play(entity.WorldPosition);
                }
            }
#endif

            if (identifier == "")
            {
                identifier = "statuseffect";
            }

            for (int i = 0; i < useItemCount; i++)
            {
                foreach (Item item in targets.FindAll(t => t is Item).Cast <Item>())
                {
                    if (item.Removed)
                    {
                        continue;
                    }
                    item.Use(deltaTime, targets.FirstOrDefault(t => t is Character) as Character, causecharacter, identifier);
                }
            }

            if (removeItem)
            {
                foreach (Item item in targets.FindAll(t => t is Item).Cast <Item>())
                {
                    Entity.Spawner?.AddToRemoveQueue(item);
                }
            }

            if (duration > 0.0f)
            {
                DurationListElement element = new DurationListElement();
                element.Parent  = this;
                element.Timer   = duration;
                element.Entity  = entity;
                element.Targets = targets;
                if (cancelledEffects != null)
                {
                    element.CancelledEffects = cancelledEffects;
                }
                element.causecharacter = causecharacter;
                element.identifier     = identifier;

/*                    if (!target.SerializableProperties.TryGetValue(propertyNames[i], out property)) continue;
 *
 *                  if (duration > 0.0f)
 *                  {
 *                      if (GameMain.Server != null)
 *                      {
 *                          if (target is Character)
 *                          {
 *                              Character effectedcharacter = (Character)target;
 *
 *                              if (GameMain.NilMod.LogStatusEffectStun && property.Name.ToLowerInvariant() == "health" && propertyEffects[i] is float && (float)propertyEffects[i] < 0f)
 *                              {
 *                                  Barotrauma.Networking.GameServer.Log(effectedcharacter.Name + " Poisoned for " + Math.Round((float)propertyEffects[i], 2) + " health per second for " + ToolBox.SecondsToReadableTime(duration) + ".", Networking.ServerLog.MessageType.Attack);
 *                              }
 *                              else if (GameMain.NilMod.LogStatusEffectHealth && property.Name.ToLowerInvariant() == "health" && propertyEffects[i] is float && (float)propertyEffects[i] < 0f)
 *                              {
 *                                  Barotrauma.Networking.GameServer.Log(effectedcharacter.Name + " Poisoned for " + Math.Round((float)propertyEffects[i], 2) + " health per second for " + ToolBox.SecondsToReadableTime(duration) + ".", Networking.ServerLog.MessageType.Attack);
 *                              }
 *                              else if (GameMain.NilMod.LogStatusEffectBleed && property.Name.ToLowerInvariant() == "bleeding" && propertyEffects[i] is float && (float)propertyEffects[i] < 0f)
 *                              {
 *                                  Barotrauma.Networking.GameServer.Log(effectedcharacter.Name + " Poisoned for " + Math.Round((float)propertyEffects[i], 2) + " bleed per second for " + ToolBox.SecondsToReadableTime(duration) + ".", Networking.ServerLog.MessageType.Attack);
 *                              }
 *                              else if (GameMain.NilMod.LogStatusEffectOxygen && property.Name.ToLowerInvariant() == "oxygen" && propertyEffects[i] is float && (float)propertyEffects[i] < 0f)
 *                              {
 *                                  Barotrauma.Networking.GameServer.Log(effectedcharacter.Name + " Poisoned for " + Math.Round((float)propertyEffects[i], 2) + " oxygen per second for " + ToolBox.SecondsToReadableTime(duration) + ".", Networking.ServerLog.MessageType.Attack);
 *                              }
 *                          }
 *                      }*/

                DurationList.Add(element);
            }
            else
            {
/*                        if (GameMain.Server != null)
 *                      {
 *                          if (target is Character)
 *                          {
 *                              Character effectedcharacter = (Character)target;
 *
 *                              //Only show values that are not continous to a character over time, that'd get rediculous fast.
 *                              if (deltaTime == 1f)
 *                              {
 *                                  if (GameMain.NilMod.LogStatusEffectStun && property.Name.ToLowerInvariant() == "stun" && propertyEffects[i] is float && (float)propertyEffects[i] > 5f)
 *                                  {
 *                                      Barotrauma.Networking.GameServer.Log(effectedcharacter.Name + " Stunned for " + (Math.Round((float)propertyEffects[i] * (1f - effectedcharacter.Stunresistance), 2)) + " (" + Math.Round(effectedcharacter.Stunresistance * 100f, 2) + "% Resisted).", Networking.ServerLog.MessageType.Attack);
 *                                  }
 *                                  else if (GameMain.NilMod.LogStatusEffectHealth && property.Name.ToLowerInvariant() == "health" && propertyEffects[i] is float && (float)propertyEffects[i] < 5f)
 *                                  {
 *                                      Barotrauma.Networking.GameServer.Log(effectedcharacter.Name + " Poisoned for " + Math.Round((float)propertyEffects[i], 2) + " health.", Networking.ServerLog.MessageType.Attack);
 *                                  }
 *                                  else if (GameMain.NilMod.LogStatusEffectBleed && property.Name.ToLowerInvariant() == "bleeding" && propertyEffects[i] is float && (float)propertyEffects[i] < 5f)
 *                                  {
 *                                      Barotrauma.Networking.GameServer.Log(effectedcharacter.Name + " Poisoned for " + Math.Round((float)propertyEffects[i], 2) + " bleed.", Networking.ServerLog.MessageType.Attack);
 *                                  }
 *                                  else if (GameMain.NilMod.LogStatusEffectOxygen && property.Name.ToLowerInvariant() == "oxygen" && propertyEffects[i] is float && (float)propertyEffects[i] < 5f)
 *                                  {
 *                                      Barotrauma.Networking.GameServer.Log(effectedcharacter.Name + " Poisoned for " + Math.Round((float)propertyEffects[i], 2) + " oxygen.", Networking.ServerLog.MessageType.Attack);
 *                                  }
 *                              }
 *                          }
 *                      }*/

                foreach (ISerializableEntity target in targets)
                {
                    if (target is Entity targetEntity)
                    {
                        if (targetEntity.Removed)
                        {
                            continue;
                        }
                    }

                    if (target is Character)
                    {
                        for (int i = 0; i < propertyNames.Length; i++)
                        {
                            SerializableProperty property;
                            if (cancelledEffects != null && cancelledEffects.Contains(i))
                            {
                                continue;
                            }
                            if (target == null || target.SerializableProperties == null || !target.SerializableProperties.TryGetValue(propertyNames[i], out property))
                            {
                                continue;
                            }
                            float     prevstat        = 0f;
                            Character targetcharacter = target as Character;
                            Boolean   prevdead        = targetcharacter.IsDead;

                            if (propertyEffects[i].GetType() == typeof(float))
                            {
                                float propertyfloat = Convert.ToSingle(propertyEffects[i]);

                                switch (property.Name.ToLowerInvariant())
                                {
                                case "health":
                                    prevstat = targetcharacter.Health;
                                    if (propertyfloat < 0f)
                                    {
                                        targetcharacter.charRecord.DamageStat("health", -(propertyfloat * CoroutineManager.UnscaledDeltaTime), causecharacter, identifier);
                                    }
                                    break;

                                case "bleeding":
                                    if (propertyfloat > 0f)
                                    {
                                        targetcharacter.charRecord.DamageStat("bleeding", (propertyfloat * CoroutineManager.UnscaledDeltaTime), causecharacter, identifier);
                                    }
                                    break;

                                case "oxygen":
                                    prevstat = targetcharacter.Oxygen;
                                    if (propertyfloat < 0f)
                                    {
                                        targetcharacter.charRecord.DamageStat("oxygen", -(propertyfloat * CoroutineManager.UnscaledDeltaTime), causecharacter, identifier);
                                    }
                                    break;

                                case "stun":
                                    if (propertyfloat > 0f)
                                    {
                                        targetcharacter.charRecord.DamageStat("stun", (propertyfloat * CoroutineManager.UnscaledDeltaTime), causecharacter, identifier);
                                    }
                                    break;

                                case "huskinfectionstate":
                                    if (propertyfloat > 0f)
                                    {
                                        targetcharacter.charRecord.DamageStat("huskinfectionstate", (propertyfloat * CoroutineManager.UnscaledDeltaTime), causecharacter, identifier);
                                    }
                                    break;

                                default:
                                    break;
                                }
                            }

                            ApplyToProperty(property, propertyEffects[i], deltaTime);

                            if (GameMain.NilMod.EnableGriefWatcher && GameMain.Server != null && causecharacter != null)
                            {
                                Barotrauma.Networking.Client targetclient    = GameMain.Server.ConnectedClients.Find(c => c.Character == targetcharacter);
                                Barotrauma.Networking.Client attackingclient = GameMain.Server.ConnectedClients.Find(c => c.Character == causecharacter);
                                if (attackingclient != null && targetclient != null)
                                {
                                    switch (property.Name.ToLowerInvariant())
                                    {
                                    case "health":
                                        if (NilMod.NilModGriefWatcher.PlayerIncapaciteDamage)
                                        {
                                            if (!prevdead)
                                            {
                                                if (targetcharacter.IsDead)
                                                {
                                                    NilMod.NilModGriefWatcher.SendWarning(attackingclient.Character.LogName
                                                                                          + " Killed player " + targetclient.Character.LogName
                                                                                          + " via " + identifier, attackingclient);
                                                }
                                                else if (prevstat > 0f && targetcharacter.Health < 0f)
                                                {
                                                    NilMod.NilModGriefWatcher.SendWarning(attackingclient.Character.LogName
                                                                                          + " Incapacitated player " + targetclient.Character.LogName
                                                                                          + " via " + identifier, attackingclient);
                                                }
                                            }
                                        }
                                        break;

                                    case "oxygen":
                                        if (NilMod.NilModGriefWatcher.PlayerIncapaciteOxygen)
                                        {
                                            if (!prevdead)
                                            {
                                                if (targetcharacter.IsDead)
                                                {
                                                    NilMod.NilModGriefWatcher.SendWarning(attackingclient.Character.LogName
                                                                                          + " Killed player " + targetclient.Character.LogName
                                                                                          + " via " + identifier, attackingclient);
                                                }
                                                else if (prevstat > 0f && targetcharacter.Oxygen < 0f)
                                                {
                                                    NilMod.NilModGriefWatcher.SendWarning(attackingclient.Character.LogName
                                                                                          + " Incapacitated player " + targetclient.Character.LogName
                                                                                          + " via " + identifier, attackingclient);
                                                }
                                            }
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else if (target is Items.Components.ItemComponent && GameMain.Server != null && causecharacter != null)
                    {
                        for (int i = 0; i < propertyNames.Length; i++)
                        {
                            SerializableProperty property;
                            if (cancelledEffects != null && cancelledEffects.Contains(i))
                            {
                                continue;
                            }
                            if (target == null || target.SerializableProperties == null || !target.SerializableProperties.TryGetValue(propertyNames[i], out property))
                            {
                                continue;
                            }
                            Items.Components.ItemComponent targetitemcomponent = target as Items.Components.ItemComponent;
                            Networking.Client attackingclient = GameMain.Server.ConnectedClients.Find(c => c.Character == causecharacter);

                            Items.Components.Door door = targetitemcomponent as Items.Components.Door;
                            Boolean previsStuck        = false;
                            //Door stuck griefing here
                            if (door != null)
                            {
                                if (propertyNames[i].ToLowerInvariant() == "stuck")
                                {
                                    previsStuck = door.IsStuck;
                                }
                            }

                            ApplyToProperty(property, propertyEffects[i], deltaTime);

                            //Door stuck griefing here
                            if (door != null)
                            {
                                if (propertyNames[i].ToLowerInvariant() == "stuck")
                                {
                                    if (previsStuck != door.IsStuck)
                                    {
                                        if (door.IsStuck)
                                        {
                                            Networking.GameServer.Log(causecharacter.LogName
                                                                      + (door.LinkedGap != null && door.LinkedGap.IsRoomToRoom ? " sealed interior " : " sealed exterior ")
                                                                      + door.Item.Name, Networking.ServerLog.MessageType.ItemInteraction);

                                            if (GameMain.NilMod.EnableGriefWatcher && NilMod.NilModGriefWatcher.DoorStuck && attackingclient != null)
                                            {
                                                NilMod.NilModGriefWatcher.SendWarning(
                                                    attackingclient.Character.LogName
                                                    + (door.LinkedGap != null && door.LinkedGap.IsRoomToRoom ? " sealed interior " : " sealed exterior ")
                                                    + door.Item.Name
                                                    + " via " + identifier, attackingclient);
                                            }
                                        }
                                        else
                                        {
                                            Networking.GameServer.Log(causecharacter.LogName
                                                                      + (door.LinkedGap != null && door.LinkedGap.IsRoomToRoom ? " unsealed interior " : " unsealed exterior ")
                                                                      + door.Item.Name, Networking.ServerLog.MessageType.ItemInteraction);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < propertyNames.Length; i++)
                        {
                            SerializableProperty property;
                            if (cancelledEffects != null && cancelledEffects.Contains(i))
                            {
                                continue;
                            }
                            if (target == null || target.SerializableProperties == null || !target.SerializableProperties.TryGetValue(propertyNames[i], out property))
                            {
                                continue;
                            }

                            ApplyToProperty(property, propertyEffects[i], deltaTime);
                        }
                    }
                }
            }

            if (explosion != null)
            {
                if (identifier == "statuseffect")
                {
                    explosion.Explode(entity.WorldPosition, causecharacter, "");
                }
                else
                {
                    explosion.Explode(entity.WorldPosition, causecharacter, identifier);
                }
            }


            Hull hull = null;
            if (entity is Character)
            {
                hull = ((Character)entity).AnimController.CurrentHull;
            }
            else if (entity is Item)
            {
                hull = ((Item)entity).CurrentHull;
            }

            if (FireSize > 0.0f)
            {
                var fire = new FireSource(entity.WorldPosition, hull);

                fire.Size = new Vector2(FireSize, fire.Size.Y);
            }

#if CLIENT
            foreach (ParticleEmitter emitter in particleEmitters)
            {
                emitter.Emit(deltaTime, entity.WorldPosition, hull);
            }
#endif
        }
예제 #20
0
        public void ServerRead(ClientNetObject type, NetBuffer msg, Barotrauma.Networking.Client c)
        {
            List <Item> prevItems = new List <Item>(Items);

            ushort[] newItemIDs = new ushort[capacity];

            for (int i = 0; i < capacity; i++)
            {
                newItemIDs[i] = msg.ReadUInt16();
            }

            if (c == null || c.Character == null)
            {
                return;
            }

            if (!c.Character.CanAccessInventory(this))
            {
                //create a network event to correct the client's inventory state
                //otherwise they may have an item in their inventory they shouldn't have been able to pick up,
                //and receiving an event for that inventory later will cause the item to be dropped
                CreateNetworkEvent();
                for (int i = 0; i < capacity; i++)
                {
                    var item = Entity.FindEntityByID(newItemIDs[i]) as Item;
                    if (item == null)
                    {
                        continue;
                    }
                    if (item.ParentInventory != null && item.ParentInventory != this)
                    {
                        item.ParentInventory.CreateNetworkEvent();
                    }
                }
                return;
            }

            List <Inventory> prevItemInventories = new List <Inventory>(Items.Select(i => i?.ParentInventory));

            for (int i = 0; i < capacity; i++)
            {
                Item newItem = newItemIDs[i] == 0 ? null : Entity.FindEntityByID(newItemIDs[i]) as Item;
                prevItemInventories.Add(newItem?.ParentInventory);

                if (newItemIDs[i] == 0 || (newItem != Items[i]))
                {
                    if (Items[i] != null)
                    {
                        Items[i].Drop();
                    }
                    System.Diagnostics.Debug.Assert(Items[i] == null);
                }
            }

            for (int i = 0; i < capacity; i++)
            {
                if (newItemIDs[i] > 0)
                {
                    var item = Entity.FindEntityByID(newItemIDs[i]) as Item;
                    if (item == null || item == Items[i])
                    {
                        continue;
                    }

                    if (GameMain.Server != null)
                    {
                        var holdable = item.GetComponent <Holdable>();
                        if (holdable != null && !holdable.CanBeDeattached())
                        {
                            continue;
                        }

                        if (!item.CanClientAccess(c))
                        {
                            continue;
                        }
                    }
                    TryPutItem(item, i, true, true, c.Character, false);
                }
            }

            CreateNetworkEvent();
            foreach (Inventory prevInventory in prevItemInventories.Distinct())
            {
                if (prevInventory != this)
                {
                    prevInventory?.CreateNetworkEvent();
                }
            }

            foreach (Item item in Items.Distinct())
            {
                if (item == null)
                {
                    continue;
                }
                if (!prevItems.Contains(item))
                {
                    if (Owner == c.Character)
                    {
                        GameServer.Log(c.Character.LogName + " picked up " + item.Name, ServerLog.MessageType.Inventory);
                    }
                    else
                    {
                        GameServer.Log(c.Character.LogName + " placed " + item.Name + " in " + Owner, ServerLog.MessageType.Inventory);
                    }
                }
            }
            foreach (Item item in prevItems.Distinct())
            {
                if (item == null)
                {
                    continue;
                }
                if (!Items.Contains(item))
                {
                    if (Owner == c.Character)
                    {
                        GameServer.Log(c.Character.LogName + " dropped " + item.Name, ServerLog.MessageType.Inventory);
                    }
                    else
                    {
                        GameServer.Log(c.Character.LogName + " removed " + item.Name + " from " + Owner, ServerLog.MessageType.Inventory);
                    }
                }
            }
        }
예제 #21
0
        public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f)
        {
            if (isStuck)
            {
                return;
            }

            bool wasOpen = predictedState == null ? isOpen : predictedState.Value;

            if (connection.Name == "toggle")
            {
                SetState(!wasOpen, false, true);
            }
            else if (connection.Name == "set_state")
            {
                SetState(signal != "0", false, true);
            }

            bool newState = predictedState == null ? isOpen : predictedState.Value;

            if (GameMain.Server != null && sender != null && wasOpen != newState)
            {
                if (linkedGap != null && !linkedGap.IsRoomToRoom)
                {
                    if (CoroutineManager.IsCoroutineRunning("WarnAirlockLeftOpen_" + item.ID))
                    {
                        CoroutineManager.StopCoroutines("WarnAirlockLeftOpen_" + item.ID);
                    }

                    //This is on a respawn shuttle
                    if (GameMain.Server.RespawnManager != null && GameMain.Server.RespawnManager.Submarine != null &&
                        item.Submarine == GameMain.Server.RespawnManager.Submarine)
                    {
                        GameServer.Log(sender.LogName + (newState ? " opened respawn shuttle exterior " : " closed respawn shuttle exterior ") + item.Name, ServerLog.MessageType.ItemInteraction);

                        if (GameMain.NilMod.EnableGriefWatcher && newState)
                        {
                            Barotrauma.Networking.Client warnedclient = GameMain.Server.ConnectedClients.Find(c => c.Character == sender);

                            CoroutineManager.StartCoroutine(WarnAirlockLeftOpen(warnedclient, this, true), "WarnAirlockLeftOpen_" + item.ID);
                        }
                    }
                    //This is a regular shuttle or submarine
                    else if (item.Submarine != null)
                    {
                        GameServer.Log(sender.LogName + (newState ? " opened " + item.Submarine.Name + " exterior " : " closed " + item.Submarine.Name + " exterior ") + item.Name, ServerLog.MessageType.ItemInteraction);

                        if (GameMain.NilMod.EnableGriefWatcher && newState)
                        {
                            Barotrauma.Networking.Client warnedclient = GameMain.Server.ConnectedClients.Find(c => c.Character == sender);

                            CoroutineManager.StartCoroutine(WarnAirlockLeftOpen(warnedclient, this, false), "WarnAirlockLeftOpen_" + item.ID);
                        }
                    }
                }
                else
                {
                    //This is on a respawn shuttle
                    if (GameMain.Server.RespawnManager != null && GameMain.Server.RespawnManager.Submarine != null &&
                        item.Submarine == GameMain.Server.RespawnManager.Submarine)
                    {
                        GameServer.Log(sender.LogName + (newState ? " opened respawn shuttle interior " : " closed respawn shuttle interior ") + item.Name, ServerLog.MessageType.ItemInteraction);
                    }
                    //This is a regular shuttle or submarine
                    else if (item.Submarine != null)
                    {
                        GameServer.Log(sender.LogName + (newState ? " opened " + item.Submarine.Name + " interior " : " closed " + item.Submarine.Name + " interior ") + item.Name, ServerLog.MessageType.ItemInteraction);
                    }
                }
            }
        }