private static Dictionary <int, WeaponInfo> QueryDic(Table weaponTable) { var selected1 = from info in ItemSys.GetInfos() where info.IsWeapon select info; var selected2 = from row in weaponTable join info in selected1 on(int) row["id"].Data equals info.Id.Id select new { info.Id, weaponInfo = new WeaponInfo((WeaponType)Enum.Parse(typeof(WeaponType), row["type"]), info.WeaponPrefabPath) }; return(selected2.ToDictionary(x => x.Id.Id, x => x.weaponInfo)); }
public void Drop(ItemGroup group) { var prefabPath = ItemSys.GetInfo(group.Id).PickPrefabPath; if (prefabPath.IsNullOrEmpty()) { prefabPath = Config.DefaultPickupableItemAssetPath; } var item = GameObjectPool.Get <PickupableItem>(prefabPath); var rot = _Rot(); var force = rot * Vector3.forward * _LaunchForce; item.Launch(_Pos(), rot, force, group); }
public void SetItem(ItemGroup itemGroup) { var itemInfo = ItemSys.GetInfo(itemGroup.Id); if (_CurItemGroup.Id != itemGroup.Id) { var texture = _CurItemGroup.Id == 0 ? null : BundleSys.GetAsset<Texture>(itemInfo.PackageCellTexturePath); _Texture.texture = new NTexture(texture); } if(_CurItemGroup.Count!=itemGroup.Count) _Num.text = itemGroup.Count.ToString(); _CurItemGroup = itemGroup; }
public override ItemGroup PutItemInto(int index, ItemGroup itemGroup) { itemGroup = itemGroup.ToValid(); var result = _Belt[index].Group; if (itemGroup.IsEmpty()) { DestroyWeapon(index); return(result); } // 源物品非武器不能添加 // 目标单元格类型不正确不能添加 if (!_WeaponInfoDic.TryGetValue(itemGroup.Id, out var info) || info.Type != _Belt[index].Type) { return(itemGroup); } var preId = result.Id; var maxStack = ItemSys.GetInfo(itemGroup.Id).MaxStackNum; if (_Belt[index].Group.Id != 0) { _Belt[index].Group.Id = itemGroup.Id; } _ItemCellChangedList.Clear(); _ItemChangedDic.Clear(); if (_Belt[index].Group.Id != itemGroup.Id) { // 交换操作无法完成不能添加 if (itemGroup.Count > maxStack) { return(itemGroup); } result = _Belt[index].Group; _ItemChangedDic.ModifyIntDic(result.Id, -result.Count); _Belt[index].Group = itemGroup; _ItemCellChangedList.Add(index); } else { var take = Mathf.Min(maxStack - _Belt[index].Group.Count, itemGroup.Count); _Belt[index].Group.Count += take; itemGroup.Count -= take; _ItemChangedDic.ModifyIntDic(itemGroup.Id, take); if (take != 0) { _ItemCellChangedList.Add(index); } } if (preId != _Belt[index].Group.Id) { DestroyWeapon(index); _Belt[index].Weapon = CreateWeaponObj(_Belt[index].Group.Id); if (_CurWeapon == index) { TakeOutWeapon(index); } } if (_ItemCellChangedList.Count != 0) { InvokeOnItemCellChanged( new PackageItemChangedInfo( _ItemCellChangedList, ToChangedItemGroups(_ItemChangedDic))); } return(result); }
public override PackageOperation PutItem(params ItemGroup[] groups) { _ItemChangedDic.Clear(); _ItemCellChangedList.Clear(); _RemainingList.Clear(); for (int i = 0; i < groups.Length; i++) { var g = groups[i].ToValid(); if (g.Id == 0 || !IsWeapon(g.Id)) { continue; } _RemainingList.Add(g); _ItemChangedDic.Add(g.Id, _RemainingList.Count - 1); } var result = new PackageOperation( JumpOverInvalidItem(_RemainingList), _ItemCellChangedList, ToChangedItemGroups(_ItemChangedDic)); var remainingCount = _RemainingList.Count; for (int curCellIndex = 0; curCellIndex < _RemainingList.Count; curCellIndex++) { var curCell = _Belt[curCellIndex]; var curSrcItemIndex = FindAvailableGroup(_RemainingList, curCell.Type); if (curSrcItemIndex == -1) { continue; } if (curCell.Group.Id == 0) { curCell.Group.Id = _RemainingList[curSrcItemIndex].Id; } if (_ItemChangedDic.TryGetValue(curCell.Group.Id, out curSrcItemIndex)) { var maxStack = ItemSys.GetInfo(curCell.Group.Id).MaxStackNum; var curSrcItem = _RemainingList[curSrcItemIndex]; if (curSrcItem.Count != 0) { var take = Mathf.Min(curSrcItem.Count, maxStack - curCell.Group.Count); curSrcItem.Count -= take; curCell.Group.Count += take; if (take != 0) { _ItemCellChangedList.Add(curCellIndex); _ItemChangedDic.ModifyIntDic(curCell.Group.Id, take); } _Belt[curCellIndex] = curCell; _RemainingList[curSrcItemIndex] = curSrcItem; if (curSrcItem.Count == 0) { remainingCount--; if (remainingCount == 0) { break; } } } } } foreach (var i in _ItemCellChangedList) { if (_Belt[i].Weapon != null) { continue; } _Belt[i].Weapon = CreateWeaponObj(_Belt[i].Group.Id); if (i == _CurWeapon) { _Belt[i].Weapon.TakeOut(); } } if (_CurWeapon == -1) { TakeOutWeapon(FindFirstAvailableWeapon(0)); } if (_ItemCellChangedList.Count != 0) { InvokeOnItemCellChanged(result.PackageItemChangedInfo); } return(result); }
public override bool PutItemCheck(params ItemGroup[] groups) { _ItemChangedDic.Clear(); _RemainingList.Clear(); for (int i = 0; i < groups.Length; i++) { var g = groups[i].ToValid(); if (!IsWeapon(g.Id)) { return(false); } if (g.Id == 0) { continue; } _RemainingList.Add(g); _ItemChangedDic.Add(g.Id, _RemainingList.Count - 1); } if (_RemainingList.Count == 0) { return(true); } var remainingCount = _RemainingList.Count; foreach (var c in _Belt) { var curCell = c; var curSrcItemIndex = FindAvailableGroup(_RemainingList, curCell.Type); if (curSrcItemIndex == -1) { continue; } if (curCell.Group.Id == 0) { curCell.Group.Id = _RemainingList[curSrcItemIndex].Id; } if (!_ItemChangedDic.TryGetValue(curCell.Group.Id, out curSrcItemIndex)) { continue; } var maxStack = ItemSys.GetInfo(curCell.Group.Id).MaxStackNum; var g = _RemainingList[curSrcItemIndex]; if (g.Count != 0) { var take = Mathf.Min(g.Count, maxStack - curCell.Group.Count); g.Count -= take; _RemainingList[curSrcItemIndex] = g; if (g.Count != 0) { continue; } remainingCount--; if (remainingCount <= 0) { break; } } } return(remainingCount <= 0); }