Example #1
0
            /// <summary>
            /// Equip the equipment in the slot.
            /// </summary>
            /// <param name="slotType">The slot of the equipment</param>
            /// <param name="equipment">The equipment to be equipped.</param>
            /// <param name="previousEquipment">The previous equipment that was equipped.</param>
            /// <returns>Return true if the equipment could be equipped properly. Exception if any error occured.</returns>
            public bool Equip(Equipment equipment, out Equipment previousEquipment)
            {
                if (Equipments.TryGetValue(equipment.EquipmentData.SlotType, out Attachment attachment))
                {
                    previousEquipment = null;

                    if (attachment.IsAttached && !Unequip(attachment, out previousEquipment))
                    {
                        throw new UnityException("The Unequip method returned false, there is a problem, please verify.");
                    }

                    attachment.Attach(transform, equipment);

                    if (equipment.EquipmentData.HideBodyPart)
                    {
                        _actor.Body.DisplayBodyParts(equipment.EquipmentData.SlotType, false);
                    }

                    _actor.Statistics.UpdateStatistics(equipment.EquipmentData.EquipmentStats.Statistics, true);

                    OnEquipmentAddedEvent?.Invoke(equipment);

                    return(true);
                }
                else
                {
                    throw new UnityException("The slot is not defined in this Equipment, please verify.");
                }
            }
        /// <summary>
        /// 指定したコネクション名に装備可能なEquipmentを取得する
        /// </summary>
        /// <returns></returns>
        public IEnumerable <T> GetEquippableEquipment <T>(string connectionName) where T : IEquipment
        {
            if (Equipments.TryGetValue(connectionName, out var wareEquipment))
            {
                return(X4Database.Instance.Ware.GetAll <T>()
                       .Where(x => !x.EquipmentTags.Except(wareEquipment.Tags).Any()));
            }

            return(Enumerable.Empty <T>());
        }
Example #3
0
 /// <summary>
 /// Unequip the Equipment from the slot.
 /// </summary>
 /// <param name="slotType">The slot type</param>
 /// <param name="equipment">The equipment that will be unequipped.</param>
 /// <returns>Return true if there is an equipment attached. Else false.</returns>
 public bool Unequip(SlotType slotType, out Equipment equipment)
 {
     if (Equipments.TryGetValue(slotType, out Attachment attachment))
     {
         return(Unequip(attachment, out equipment));
     }
     else
     {
         throw new UnityException("The slot is not defined in this Equipment, please verify.");
     }
 }
Example #4
0
        /// <summary>
        /// 指定したコネクション名に装備可能なEquipmentを取得する
        /// </summary>
        /// <returns></returns>
        public IEnumerable <T> GetEquippableEquipment <T>(string connectionName) where T : IEquipment
        {
            // 指定したコネクション名に装備可能な装備は存在するか?
            if (Equipments.TryGetValue(connectionName, out var wareEquipment))
            {
                // デフォルトのロードアウトは存在するか?
                if (Loadouts.TryGetValue("default", out var loadouts))
                {
                    bool matched = false;

                    // デフォルトのロードアウトの内、指定したコネクション名と同じグループ名を持つもので装備可能なものを取得する
                    var shipLoadout = loadouts.FirstOrDefault(x =>
                                                              (x.GroupName == wareEquipment.GroupName && wareEquipment.CanEquipped(x.Equipment)) ||
                                                              (string.IsNullOrEmpty(x.GroupName) && wareEquipment.CanEquipped(x.Equipment))
                                                              );
                    if (shipLoadout is not null)
                    {
                        // 同じグループ名の装備は指定した型と一致するか?
                        if (shipLoadout.Equipment is T ret)
                        {
                            matched = true;
                            yield return(ret);
                        }
                    }

                    if (matched)
                    {
                        yield break;
                    }
                }


                var equipments = X4Database.Instance.Ware.GetAll <T>()
                                 .Where(x => wareEquipment.CanEquipped(x));
                foreach (var equipment in equipments)
                {
                    yield return(equipment);
                }
            }
        }