Beispiel #1
0
 private Stats EquippedItemModifiers()
 {
     return(AllItemSlots
            .Where(SlotHasItemEquipped)
            .Select(x => x.Value.Stats)
            .Aggregate(new Stats(), (collector, next) => collector + next));
 }
Beispiel #2
0
        public Player()
        {
            BaseStats = new Stats(100, 100, 100);
            Armor     = new ReactiveProperty <Item>();
            Weapon    = new ReactiveProperty <Item>();
            Shield    = new ReactiveProperty <Item>();
            Accessory = new ReactiveProperty <Item>();
            Inventory = new ReactiveCollection <Item>();

            InventoryWeight = Observable.Merge(new[] {
                AllItemSlots.Merge().Select(_ => new Unit()),
                Inventory.ObserveCountChanged().Select(_ => new Unit()),
            })
                              .StartWith(new Unit())
                              .Select(_ =>
                                      Inventory
                                      .Concat(AllItemSlots.Where(SlotHasItemEquipped).Select(x => x.Value))
                                      .Aggregate(0, (collector, next) => collector + next.Weight)
                                      )
                              .ToReadOnlyReactiveProperty();

            Stats = AllItemSlots
                    .Merge()
                    .CombineLatest(InventoryWeight, Tuple.Create)
                    .Select(x => {
                var invWeight     = x.Item2;
                var allWeight     = GameDataManager.instance.AllItemsWeight;
                var modifiedStats = BaseStats + EquippedItemModifiers();
                var weightBurden  = GameDataManager.instance.GetPlayerTunedWeightBurden(invWeight);
                var finalStats    = new Stats(modifiedStats.Hp, modifiedStats.Mp, modifiedStats.Speed * (1 - weightBurden));
                Debug.Log($"Update stats, modified:{modifiedStats} invWeight:{invWeight} allWeight:{allWeight} normalWeight:{invWeight / (float)allWeight} weightBurden:{weightBurden} finalStats:{finalStats}");
                return(finalStats);
            })
                    .ToReadOnlyReactiveProperty();
        }