public AbilityConditionHasStatusTag(CharacterTalent characterTalent, XElement conditionElement) : base(characterTalent, conditionElement)
 {
     tag = conditionElement.GetAttributeString("tag", "");
     if (string.IsNullOrEmpty(tag))
     {
         DebugConsole.AddWarning($"Error in talent \"{characterTalent.Prefab.OriginalName}\" - tag not defined in AbilityConditionHasStatusTag.");
     }
 }
Ejemplo n.º 2
0
        public CharacterAbilityIncreaseSkill(CharacterAbilityGroup characterAbilityGroup, XElement abilityElement) : base(characterAbilityGroup, abilityElement)
        {
            skillIdentifier = abilityElement.GetAttributeString("skillidentifier", "").ToLowerInvariant();
            skillIncrease   = abilityElement.GetAttributeFloat("skillincrease", 0f);

            if (string.IsNullOrEmpty(skillIdentifier))
            {
                DebugConsole.ThrowError($"Error in talent \"{characterAbilityGroup.CharacterTalent.DebugIdentifier}\" - skill identifier not defined in CharacterAbilityIncreaseSkill.");
            }
            if (MathUtils.NearlyEqual(skillIncrease, 0))
            {
                DebugConsole.AddWarning($"Possible error in talent \"{characterAbilityGroup.CharacterTalent.DebugIdentifier}\" - skill increase set to 0.");
            }
        }
        protected override bool MatchesConditionSpecific(AbilityObject abilityObject)
        {
            if (abilityObject is AbilityAttackData attackData)
            {
                Item item = attackData?.SourceAttack?.SourceItem;

                if (item == null)
                {
                    DebugConsole.AddWarning($"Source Item was not found in {this} for talent {characterTalent.DebugIdentifier}!");
                    return(false);
                }

                if (!string.IsNullOrEmpty(itemIdentifier))
                {
                    if (item.prefab.Identifier != itemIdentifier)
                    {
                        return(false);
                    }
                }

                if (tags.Any())
                {
                    if (!tags.All(t => item.HasTag(t)))
                    {
                        return(false);
                    }
                }

                switch (weapontype)
                {
                case WeaponType.Melee:
                    return(item.GetComponent <MeleeWeapon>() != null);

                case WeaponType.Ranged:
                    return(item.GetComponent <RangedWeapon>() != null);
                }

                return(true);
            }
            else
            {
                LogAbilityConditionError(abilityObject, typeof(AbilityAttackData));
                return(false);
            }
        }
Ejemplo n.º 4
0
        private void Send(byte[] buf, int length, Steamworks.P2PSend sendType)
        {
            bool successSend = Steamworks.SteamNetworking.SendP2PPacket(hostSteamId, buf, length + 4, 0, sendType);

            sentBytes += length + 4;
            if (!successSend)
            {
                if (sendType != Steamworks.P2PSend.Reliable)
                {
                    DebugConsole.Log("WARNING: message couldn't be sent unreliably, forcing reliable send (" + length.ToString() + " bytes)");
                    sendType    = Steamworks.P2PSend.Reliable;
                    successSend = Steamworks.SteamNetworking.SendP2PPacket(hostSteamId, buf, length + 4, 0, sendType);
                    sentBytes  += length + 4;
                }
                if (!successSend)
                {
                    DebugConsole.AddWarning("Failed to send message to remote peer! (" + length.ToString() + " bytes)");
                }
            }
        }
Ejemplo n.º 5
0
        public bool RequestAlBuffers()
        {
            if (AlBuffer != 0)
            {
                return(false);
            }
            int alError;

            lock (bufferPool)
            {
                while (bufferPool.Count < 2 && BuffersGenerated < MaxBuffers)
                {
                    Al.GenBuffer(out uint newBuffer);
                    alError = Al.GetError();
                    if (alError != Al.NoError)
                    {
                        DebugConsole.AddWarning($"Error when generating sound buffer: {Al.GetErrorString(alError)}. {BuffersGenerated} buffer(s) were generated. No more sound buffers will be generated.");
                        BuffersGenerated = MaxBuffers;
                    }
                    else if (!Al.IsBuffer(newBuffer))
                    {
                        DebugConsole.AddWarning($"Error when generating sound buffer: result is not a valid buffer. {BuffersGenerated} buffer(s) were generated. No more sound buffers will be generated.");
                        BuffersGenerated = MaxBuffers;
                    }
                    else
                    {
                        bufferPool.Add(newBuffer);
                        BuffersGenerated++;
                        if (BuffersGenerated >= MaxBuffers)
                        {
                            DebugConsole.AddWarning($"{BuffersGenerated} buffer(s) were generated. No more sound buffers will be generated.");
                        }
                    }
                }

                if (bufferPool.Count >= 2)
                {
                    AlBuffer = bufferPool.First();
                    bufferPool.Remove(AlBuffer);
                    AlMuffledBuffer = bufferPool.First();
                    bufferPool.Remove(AlMuffledBuffer);
                    return(true);
                }
            }

            //can't generate any more OpenAL buffers! we'll have to steal a buffer from someone...
            foreach (var otherSound in sound.Owner.LoadedSounds)
            {
                if (otherSound == sound)
                {
                    continue;
                }
                if (otherSound.IsPlaying())
                {
                    continue;
                }
                if (otherSound.Buffers == null)
                {
                    continue;
                }
                if (otherSound.Buffers.AlBuffer == 0)
                {
                    continue;
                }

                // Dispose all channels that are holding
                // a reference to these buffers, otherwise
                // an INVALID_OPERATION error will be thrown
                // when attempting to set the buffer data later.
                // Having the sources not play is not enough,
                // as OpenAL assumes that you may want to call
                // alSourcePlay without reassigning the buffer.
                otherSound.Owner.KillChannels(otherSound);

                AlBuffer                           = otherSound.Buffers.AlBuffer;
                AlMuffledBuffer                    = otherSound.Buffers.AlMuffledBuffer;
                otherSound.Buffers.AlBuffer        = 0;
                otherSound.Buffers.AlMuffledBuffer = 0;

                // For performance reasons, sift the current sound to
                // the end of the loadedSounds list, that way it'll
                // be less likely to have its buffers stolen, which
                // means less reuploads for frequently played sounds.
                sound.Owner.MoveSoundToPosition(sound, sound.Owner.LoadedSoundCount - 1);

                if (!Al.IsBuffer(AlBuffer))
                {
                    throw new Exception(sound.Filename + " has an invalid buffer!");
                }
                if (!Al.IsBuffer(AlMuffledBuffer))
                {
                    throw new Exception(sound.Filename + " has an invalid muffled buffer!");
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 6
0
        partial void InitProjSpecific(XElement element)
        {
            slotIcons = new Sprite[capacity];
            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "topsprite":
                    inventoryTopSprite = new Sprite(subElement);
                    break;

                case "backsprite":
                    inventoryBackSprite = new Sprite(subElement);
                    break;

                case "bottomsprite":
                    inventoryBottomSprite = new Sprite(subElement);
                    break;

                case "containedstateindicator":
                    ContainedStateIndicator = new Sprite(subElement);
                    break;

                case "containedstateindicatorempty":
                    ContainedStateIndicatorEmpty = new Sprite(subElement);
                    break;

                case "sloticon":
                    int    index = subElement.GetAttributeInt("slotindex", -1);
                    Sprite icon  = new Sprite(subElement);
                    for (int i = 0; i < capacity; i++)
                    {
                        if (i == index || index == -1)
                        {
                            slotIcons[i] = icon;
                        }
                    }
                    break;
                }
            }

            if (string.IsNullOrEmpty(ContainedStateIndicatorStyle))
            {
                //if neither a style or a custom sprite is defined, use default style
                if (ContainedStateIndicator == null)
                {
                    IndicatorStyle = GUI.Style.GetComponentStyle("ContainedStateIndicator.Default");
                }
            }
            else
            {
                IndicatorStyle = GUI.Style.GetComponentStyle("ContainedStateIndicator." + ContainedStateIndicatorStyle);
                if (ContainedStateIndicator != null || ContainedStateIndicatorEmpty != null)
                {
                    DebugConsole.AddWarning($"Item \"{item.Name}\" defines both a contained state indicator style and a custom indicator sprite. Will use the custom sprite...");
                }
            }
            if (GuiFrame == null)
            {
                //if a GUIFrame is not defined in the xml,
                //we create a full-screen frame and let the inventory position itself on it
                GuiFrame = new GUIFrame(new RectTransform(Vector2.One, GUI.Canvas), style: null)
                {
                    CanBeFocused = false
                };
                guiCustomComponent = new GUICustomComponent(new RectTransform(Vector2.One, GuiFrame.RectTransform),
                                                            onDraw: (SpriteBatch spriteBatch, GUICustomComponent component) => { Inventory.Draw(spriteBatch); },
                                                            onUpdate: null)
                {
                    CanBeFocused = false
                };
                GuiFrame.RectTransform.ParentChanged += OnGUIParentChanged;
            }
            else
            {
                //if a GUIFrame has been defined, draw the inventory inside it
                CreateGUI();
            }

            containedSpriteDepths = element.GetAttributeFloatArray("containedspritedepths", new float[0]);
        }
Ejemplo n.º 7
0
        private void HandleDataMessage(IReadMessage inc)
        {
            if (!isActive)
            {
                return;
            }

            UInt64         recipientSteamId = inc.ReadUInt64();
            DeliveryMethod deliveryMethod   = (DeliveryMethod)inc.ReadByte();

            int p2pDataStart = inc.BytePosition;

            byte incByte = inc.ReadByte();

            bool isCompressed = (incByte & (byte)PacketHeader.IsCompressed) != 0;
            bool isConnectionInitializationStep = (incByte & (byte)PacketHeader.IsConnectionInitializationStep) != 0;
            bool isDisconnectMessage            = (incByte & (byte)PacketHeader.IsDisconnectMessage) != 0;
            bool isServerMessage    = (incByte & (byte)PacketHeader.IsServerMessage) != 0;
            bool isHeartbeatMessage = (incByte & (byte)PacketHeader.IsHeartbeatMessage) != 0;

            if (recipientSteamId != selfSteamID)
            {
                if (!isServerMessage)
                {
                    DebugConsole.ThrowError("Received non-server message meant for remote peer");
                    return;
                }

                RemotePeer peer = remotePeers.Find(p => p.SteamID == recipientSteamId);

                if (peer == null)
                {
                    return;
                }

                if (isDisconnectMessage)
                {
                    DisconnectPeer(peer, inc.ReadString());
                    return;
                }

                Steamworks.P2PSend sendType;
                switch (deliveryMethod)
                {
                case DeliveryMethod.Reliable:
                case DeliveryMethod.ReliableOrdered:
                    //the documentation seems to suggest that the Reliable send type
                    //enforces packet order (TODO: verify)
                    sendType = Steamworks.P2PSend.Reliable;
                    break;

                default:
                    sendType = Steamworks.P2PSend.Unreliable;
                    break;
                }

                byte[] p2pData;

                if (isConnectionInitializationStep)
                {
                    p2pData    = new byte[inc.LengthBytes - p2pDataStart + 8];
                    p2pData[0] = inc.Buffer[p2pDataStart];
                    Lidgren.Network.NetBitWriter.WriteUInt64(SteamManager.CurrentLobbyID, 64, p2pData, 8);
                    Array.Copy(inc.Buffer, p2pDataStart + 1, p2pData, 9, inc.LengthBytes - p2pDataStart - 1);
                }
                else
                {
                    p2pData = new byte[inc.LengthBytes - p2pDataStart];
                    Array.Copy(inc.Buffer, p2pDataStart, p2pData, 0, p2pData.Length);
                }

                if (p2pData.Length + 4 >= MsgConstants.MTU)
                {
                    DebugConsole.Log("WARNING: message length comes close to exceeding MTU, forcing reliable send (" + p2pData.Length.ToString() + " bytes)");
                    sendType = Steamworks.P2PSend.Reliable;
                }

                bool successSend = Steamworks.SteamNetworking.SendP2PPacket(recipientSteamId, p2pData, p2pData.Length, 0, sendType);
                sentBytes += p2pData.Length;

                if (!successSend)
                {
                    if (sendType != Steamworks.P2PSend.Reliable)
                    {
                        DebugConsole.Log("WARNING: message couldn't be sent unreliably, forcing reliable send (" + p2pData.Length.ToString() + " bytes)");
                        sendType    = Steamworks.P2PSend.Reliable;
                        successSend = Steamworks.SteamNetworking.SendP2PPacket(recipientSteamId, p2pData, p2pData.Length, 0, sendType);
                        sentBytes  += p2pData.Length;
                    }
                    if (!successSend)
                    {
                        DebugConsole.AddWarning("Failed to send message to remote peer! (" + p2pData.Length.ToString() + " bytes)");
                    }
                }
            }
            else
            {
                if (isDisconnectMessage)
                {
                    DebugConsole.ThrowError("Received disconnect message from owned server");
                    return;
                }
                if (!isServerMessage)
                {
                    DebugConsole.ThrowError("Received non-server message from owned server");
                    return;
                }
                if (isHeartbeatMessage)
                {
                    return; //timeout is handled by Lidgren, ignore this message
                }
                if (isConnectionInitializationStep)
                {
                    IWriteMessage outMsg = new WriteOnlyMessage();
                    outMsg.Write(selfSteamID);
                    outMsg.Write(selfSteamID);
                    outMsg.Write((byte)(PacketHeader.IsConnectionInitializationStep));
                    outMsg.Write(Name);

                    byte[] msgToSend = (byte[])outMsg.Buffer.Clone();
                    Array.Resize(ref msgToSend, outMsg.LengthBytes);
                    ChildServerRelay.Write(msgToSend);
                    return;
                }
                else
                {
                    if (initializationStep != ConnectionInitialization.Success)
                    {
                        OnInitializationComplete?.Invoke();
                        initializationStep = ConnectionInitialization.Success;
                    }
                    UInt16       length = inc.ReadUInt16();
                    IReadMessage msg    = new ReadOnlyMessage(inc.Buffer, isCompressed, inc.BytePosition, length, ServerConnection);
                    OnMessageReceived?.Invoke(msg);

                    return;
                }
            }
        }
Ejemplo n.º 8
0
        public override bool Use(float deltaTime, Character character = null)
        {
            if (!attachable || item.body == null)
            {
                return(character == null || (character.IsKeyDown(InputType.Aim) && characterUsable));
            }
            if (character != null)
            {
                if (!characterUsable && !attachable)
                {
                    return(false);
                }
                if (!character.IsKeyDown(InputType.Aim))
                {
                    return(false);
                }
                if (!CanBeAttached(character))
                {
                    return(false);
                }

                if (LimitedAttachable)
                {
                    if (character?.Info == null)
                    {
                        DebugConsole.AddWarning("Character without CharacterInfo attempting to attach a limited attachable item!");
                        return(false);
                    }
                    Vector2   attachPos    = GetAttachPosition(character, useWorldCoordinates: true);
                    Structure attachTarget = Structure.GetAttachTarget(attachPos);

                    int maxAttachableCount     = (int)character.Info.GetSavedStatValue(StatTypes.MaxAttachableCount, item.Prefab.Identifier);
                    int currentlyAttachedCount = Item.ItemList.Count(
                        i => i.Submarine == attachTarget?.Submarine && i.GetComponent <Holdable>() is Holdable holdable && holdable.Attached && i.Prefab.Identifier == item.prefab.Identifier);
                    if (currentlyAttachedCount >= maxAttachableCount)
                    {
#if CLIENT
                        GUI.AddMessage($"{TextManager.Get("itemmsgtotalnumberlimited")} ({currentlyAttachedCount}/{maxAttachableCount})", Color.Red);
#endif
                        return(false);
                    }
                }

                if (GameMain.NetworkMember != null)
                {
                    if (character != Character.Controlled)
                    {
                        return(false);
                    }
                    else if (GameMain.NetworkMember.IsServer)
                    {
                        return(false);
                    }
                    else
                    {
#if CLIENT
                        Vector2 attachPos = ConvertUnits.ToSimUnits(GetAttachPosition(character));
                        GameMain.Client.CreateEntityEvent(item, new object[]
                        {
                            NetEntityEvent.Type.ComponentState,
                            item.GetComponentIndex(this),
                            attachPos
                        });
#endif
                    }
                    return(false);
                }
                else
                {
                    item.Drop(character);
                    item.SetTransform(ConvertUnits.ToSimUnits(GetAttachPosition(character)), 0.0f, findNewHull: false);
                }
                AttachToWall();
            }
            return(true);
        }
Ejemplo n.º 9
0
 protected virtual void ApplyEffect()
 {
     DebugConsole.AddWarning($"Ability {this} used improperly! This ability does not have a definition for ApplyEffect");
 }
Ejemplo n.º 10
0
 protected virtual void ApplyEffect(AbilityObject abilityObject)
 {
     DebugConsole.AddWarning($"Ability {this} used improperly! This ability does not take a parameter for ApplyEffect");
 }