using AOT; using CoreGame; using CoreGame.Render; using ProtoCSClass; using UnityEngine; using UnityEngine.AI; namespace CoreGame.Render { public class DropItemSrv { public static string[] DropItemTailPath = new string[] { "Effect/CoreGame/Prefab/Eff_Beam/Eff_Drop_Trailing_White.prefab", "Effect/CoreGame/Prefab/Eff_Beam/Eff_Drop_Trailing_Blue.prefab", "Effect/CoreGame/Prefab/Eff_Beam/Eff_Drop_Trailing_Purple.prefab", "Effect/CoreGame/Prefab/Eff_Beam/Eff_Drop_Trailing_Orange.prefab", "Effect/CoreGame/Prefab/Eff_Beam/Eff_Drop_Trailing_Unique.prefab", }; public static string[] DropItemModelLightPath = new string[] { "Effect/CoreGame/Prefab/Eff_Beam/Eff_Beam_White.prefab", "Effect/CoreGame/Prefab/Eff_Beam/Eff_Beam_Blue.prefab", "Effect/CoreGame/Prefab/Eff_Beam/Eff_Beam_Purple.prefab", "Effect/CoreGame/Prefab/Eff_Beam/Eff_Beam_Orange.prefab", "Effect/CoreGame/Prefab/Eff_Beam/Eff_Beam_Unique.prefab", }; public static void SimulateCreateDropItem(CombatEntity entity) { // 目前只有怪物才会掉落物品 if (entity.hasMonster == false) return; var cfgId = entity.blackboard.unitCfgId; var tbMonster = MonsterPropDescMgr.Instance.GetConfig(cfgId); if (tbMonster == null) return; // var drops = tbMonster.dropConfig; // for (int i = 0; i < drops.Length; i++) // { // var range = RandomSrv.Range(0, 1.0f); // if (range > drops[i].Rate) // continue; // // DropItem(entity.transformProxy.position, drops[i].Id); // } } public static void CreateExactDropItem(Vector2 pos, int id, float dropRadius = BattleConst.DropItemRadius) { var dropSkillDesc = DropSkillDescMgr.Instance.GetConfig(id); // DropItem(pos, id, DropItemType.Custom, dropSkillDesc.modelPrefab, dropSkillDesc.quality, 1, // dropSkillDesc.dropType, dropSkillDesc.pickUpType, // dropSkillDesc.pickUpRange * BattleConst.TenThousandReverse, // dropSkillDesc.pickUpTime * BattleConst.TenThousandReverse, dropRadius); } public static CombatEntity DropItem(Vector2 pos, TypeIDValue32 typeIDValue) { if (typeIDValue.Type == (int)DropItemType.Equip) { var equipData = EquipDescMgr.Instance.GetConfigByGhostID(typeIDValue.Id); if (equipData != null) { return DropItem(pos, typeIDValue.Id, DropItemType.Equip, equipData.modelPrefab, (int)equipData.quality, typeIDValue.Value); } } else if (typeIDValue.Type == (int)DropItemType.Item) { var itemData = ItemDescMgr.Instance.GetConfigByGhostID(typeIDValue.Id); if (itemData != null) { return DropItem(pos, typeIDValue.Id, DropItemType.Item, itemData.modelPrefab, (int)itemData.quality, typeIDValue.Value); } } return null; } private static CombatEntity DropItem(Vector2 pos, int id, DropItemType type, string path, int quality, int cnt, DropType dropType = DropType.Default, PickUpType pickUpType = PickUpType.Instant, float pickUpRange = 0, float pickUpTime = 0, float dropRadius = BattleConst.DropItemRadius) { var de = Contexts.Combat.CreateEntity(); de.AddDropItemData(id, type, quality, cnt); if (pickUpType == PickUpType.Instant) { de.AddInstantToBeAttracted(pickUpRange); } else if (pickUpType == PickUpType.Wait) { de.AddWaitToBeAttracted(pickUpRange, pickUpTime); } var startPos = Vector2.zero; var endPos = Vector2.zero; var control = Vector2.zero; var dropDuration = 0f; var random = Vector2.right; //MathHelper.OnsideUnitCircleRandom(dropRadius); if (dropType == DropType.Default) { var halfPoint = (pos + pos + random) / 2f; startPos = pos; // 随机掉落位置 endPos = random + pos; if (NavMesh.Raycast(startPos, endPos, out var hit, NavMesh.AllAreas)) { endPos = new Vector2(hit.position.x, hit.position.y); } control = dropRadius * 1.5f * Vector2.up + halfPoint; dropDuration = BattleConst.DropItemDefaultDropDuration; } else if (dropType == DropType.StraightFall) { endPos = pos + random; if (NavMesh.Raycast(startPos, endPos, out var hit, NavMesh.AllAreas)) { endPos = new Vector2(hit.position.x, hit.position.y); } startPos = endPos + Vector2.up * BattleConst.DropItemStraightFallHeight; control = startPos; dropDuration = BattleConst.DropItemStraightFallDropDuration; } de.AddTransformProxy(startPos, Vector2.right, de); de.transformProxy.Flush(); de.AddAsset(new MainAssetParam() { path = path, parentNodeName = "RenderWorld", scaleParam = 0.3f, }, null); if (quality > (int)CommonQuality.None && quality < (int)CommonQuality.Size) { var subAssetData = SptPool.Malloc(); subAssetData.Awake(de.creationIndex, CommParamDescMgr.Instance.DropQualSFXTail.str_list[quality], BindPointType.Main, null); de.asset.PushMainPartAsset(ref subAssetData); var subAssetData2 = SptPool.Malloc(); subAssetData2.Awake(de.creationIndex, CommParamDescMgr.Instance.DropQualSFX.str_list[quality], BindPointType.Main, null); de.asset.PushMainPartAsset(ref subAssetData2); } de.AddDoDrop(dropDuration, endPos, startPos, control, BattleConst.DropItemScaleTarget, BattleConst.DropItemScale); return de; } } }