public bool UpdateOPTreeInfo() { if (null == m_Axe || m_Axe.durability <= PETools.PEMath.Epsilon) { return(false); } mFindTreeInfo = null; GlobalTreeInfo gTreeinfo = PETools.PEUtil.RayCastTree(PeCamera.mouseRay.origin - 0.5f * PeCamera.mouseRay.direction, PeCamera.mouseRay.direction, 100f); GlobalTreeInfo playerTree = PETools.PEUtil.RayCastTree(trans.existent.position + Vector3.up, trans.existent.forward, FellDis); if (null == gTreeinfo || null == playerTree || gTreeinfo._treeInfo != playerTree._treeInfo) { return(false); } if (gTreeinfo != null) { NaturalRes resFind = NaturalResAsset.NaturalRes.GetTerrainResData(gTreeinfo._treeInfo.m_protoTypeIdx + 1000); if (null != resFind) { if (resFind.m_type == 9) { mFindTreeInfo = gTreeinfo; } } } return(null != mFindTreeInfo); }
public int GetDestroyed(SkillRunner caster, float durDec, float radius) { if (!GameConfig.IsMultiMode) { NaturalRes res = NaturalResAsset.NaturalRes.GetTerrainResData(mGroundItem._treeInfo.m_protoTypeIdx + 1000); if (m_Hp > 0) { m_Hp -= durDec * res.m_duration; UITreeCut.Instance.SetSliderValue(mGroundItem._treeInfo, m_Hp / mMaxHp); //PlayerFactory.mMainPlayer.UpdateTreeHp(mGroundItem._treeInfo, m_Hp); //if (m_Hp <= 0) //{ // if (null != LSubTerrainMgr.Instance) // { // LSubTerrainMgr.DeleteTree(mGroundItem); // LSubTerrainMgr.RefreshAllLayerTerrains(); // } // else if (null != RSubTerrainMgr.Instance) // { // RSubTerrainMgr.DeleteTree(mGroundItem._treeInfo); // RSubTerrainMgr.RefreshAllLayerTerrains(); // } // TreeCutGui_N.Instance.HideWindow(); // return 101; //} } } else { //NaturalRes res = NaturalResAsset.NaturalRes.GetTerrainResData(mGroundItem._treeInfo.m_protoTypeIdx + 1000); //m_Hp -= durDec * res.m_duration; //TreeCutGui_N.Instance.SetSliderValue(m_Hp / mMaxHp); //PlayerFactory.mMainPlayer.UpdateTreeHp(mGroundItem._treeInfo, m_Hp); //if (m_Hp <= 0) //{ // if (null != RSubTerrainMgr.Instance) // { // TreeInfo treeInfo = mGroundItem._treeInfo; // //RSubTerrainMgr.DeleteTreesAtPos(mGroundItem._treeInfo.m_pos); // LogManager.Debug("RPC_C2S_GroundItemTarget: " + weaponBonus + ", " + treeInfo.m_protoTypeIdx + "," + treeInfo.m_widthScale + "," + treeInfo.m_heightScale); // caster.RPC("RPC_C2S_GroundItemTarget", weaponBonus, treeInfo.m_protoTypeIdx, treeInfo.m_widthScale, treeInfo.m_heightScale,treeInfo.m_pos); // } // TreeCutGui_N.Instance.HideWnd(); // return 100; //} // NaturalRes res = NaturalResAsset.NaturalRes.GetTerrainResData(mGroundItem._treeInfo.m_protoTypeIdx + 1000); // if (null != res) // { // TreeInfo treeInfo = mGroundItem._treeInfo; // caster.RPCServer(EPacketType.PT_InGame_SkillGroundItem, res.mCastSkill, treeInfo.m_pos, // treeInfo.m_protoTypeIdx, treeInfo.m_heightScale, treeInfo.m_widthScale); // } return(0); } return(0); }
public List <ItemSample> ReturnItems(short resGotMultiplier, int num) { List <ItemSample> reItem = new List <ItemSample>(); NaturalRes res = NaturalResAsset.NaturalRes.GetTerrainResData(mGroundItem._treeInfo.m_protoTypeIdx + 1000); ItemSample[] getItem = new ItemSample[res.m_itemsGot.Count]; for (int i = 0; i < res.m_itemsGot.Count; i++) { getItem[i] = new ItemSample(res.m_itemsGot[i].m_id, 0); } float resGet = 0; if (res.mFixedNum > 0) { resGet = res.mFixedNum; } else { resGet = resGotMultiplier + res.mSelfGetNum * mGroundItem._treeInfo.m_widthScale * mGroundItem._treeInfo.m_widthScale * mGroundItem._treeInfo.m_heightScale; } for (int numGet = 0; numGet < (int)resGet; numGet++) { int getPro = UnityEngine.Random.Range(0, 100); for (int i = 0; i < res.m_itemsGot.Count; i++) { if (getPro < res.m_itemsGot[i].m_probablity) { getItem[i].IncreaseStackCount(1); break; } } } //extra item get below, add by yinrui List <ItemSample> itemGetExtra = new List <ItemSample>(); if (res.m_extraGot.extraPercent > 0 && Random.value < resGet * res.m_extraGot.extraPercent) { for (int i = 0; i < res.m_extraGot.m_extraGot.Count; i++) { itemGetExtra.Add(new ItemSample(res.m_extraGot.m_extraGot[i].m_id, 0)); } resGet *= res.m_extraGot.extraPercent; int rand; for (int i = 0; i < resGet; i++) { rand = Random.Range(0, 100); for (int j = 0; j < res.m_extraGot.m_extraGot.Count; j++) { if (rand < res.m_extraGot.m_extraGot[j].m_probablity) { itemGetExtra[j].IncreaseStackCount(1); break; } } } } //part1 end for (int i = 0; i < res.m_itemsGot.Count; i++) { if (getItem[i].GetCount() > 0) { reItem.Add(getItem[i]); } } foreach (ItemSample data in itemGetExtra) { if (data.GetCount() > 0) { reItem.Add(data); } } //recalculation num with treeinfo's scale /*foreach(ItemSample finalGetItem in reItem) * { * int getnum = finalGetItem.GetCount(); * if(getnum == 1) * continue; * getnum = (int)(getnum * mGroundItem._treeInfo.m_widthScale * mGroundItem._treeInfo.m_heightScale); * getnum = (getnum < 1)?1:getnum; * finalGetItem.DecreaseStackCount(finalGetItem.GetCount()); * finalGetItem.CountUp(getnum); * }*/ return(reItem); }
public List <ItemSample> ReturnItems(short resGotMultiplier, int num) { NaturalRes resData; num = mRemoveList.Count; List <ItemSample> itemGridList = new List <ItemSample>(); for (int index = 0; index < num; index++) { if ((resData = NaturalRes.GetTerrainResData(mRemoveList[index].Type)) != null && resData.m_itemsGot.Count > 0) { List <float> randVars = new List <float>(); ItemSample[] itemGrids = new ItemSample[resData.m_itemsGot.Count]; for (int i = 0; i < resData.m_itemsGot.Count; i++) { itemGrids[i] = new ItemSample(resData.m_itemsGot[i].m_id, 0); } float resGet = 0; if (resData.mFixedNum > 0) { resGet = resData.mFixedNum; } else { resGet = (resGotMultiplier + resData.mSelfGetNum); } for (int i = 0; i < resGet; i++) { randVars.Add(UnityEngine.Random.Range(0, 100)); } for (int i = 0; i < randVars.Count; i++) { for (int j = 0; j < resData.m_itemsGot.Count; j++) { if (randVars[i] < resData.m_itemsGot[j].m_probablity) { itemGrids[j].IncreaseStackCount(1); break; } } } //extra item get below, add by yinrui List <ItemSample> itemGetExtra = new List <ItemSample>(); if (resData.m_extraGot.extraPercent > 0 && Random.value < resGet * resData.m_extraGot.extraPercent) { for (int i = 0; i < resData.m_extraGot.m_extraGot.Count; i++) { itemGetExtra.Add(new ItemSample(resData.m_extraGot.m_extraGot[i].m_id, 0)); } resGet *= resData.m_extraGot.extraPercent; int rand; for (int i = 0; i < resGet; i++) { rand = Random.Range(0, 100); for (int j = 0; j < resData.m_extraGot.m_extraGot.Count; j++) { if (rand < resData.m_extraGot.m_extraGot[j].m_probablity) { itemGetExtra[j].IncreaseStackCount(1); break; } } } } //part1 end for (int i = 0; i < itemGrids.Length; i++) { if (itemGrids[i].GetCount() > 0) { ItemSample findItem = itemGridList.Find(itr => itr.protoId == itemGrids[i].protoId); if (null != findItem) { findItem.IncreaseStackCount(itemGrids[i].GetCount()); } else { itemGridList.Add(itemGrids[i]); } } } //part2 foreach (ItemSample data in itemGetExtra) { if (data.GetCount() > 0) { ItemSample findItem = itemGridList.Find(itr => itr.protoId == data.protoId); if (null != findItem) { findItem.IncreaseStackCount(data.GetCount()); } else { itemGridList.Add(data); } } } //part2 end } } mRemoveList.Clear(); return(itemGridList); }
void Update(FootprintDecalMan reqDecal) { float fCurFootDistance = 0f; bool bPlaceAFootprint = false; bool bPlayerInMove = reqDecal._ctrlr.velocity.magnitude > reqDecal._thresVelOfMove; if (bPlayerInMove) { //Vector3 vecMoveDir = mMoveDirection; vecMoveDir.y = 0; Vector3 vecMoveDir = reqDecal._ctrlr.velocity; vecMoveDir.y = 0; Vector3 vecFootDistance = reqDecal._lrFoot[0].position - reqDecal._lrFoot[1].position; vecFootDistance.y = 0; fCurFootDistance = Vector3.Dot(vecFootDistance, vecMoveDir.normalized); if ((0 == reqDecal._curFoot && reqDecal._fpLastLRFootDistance > 0 && fCurFootDistance < reqDecal._fpLastLRFootDistance) || (1 == reqDecal._curFoot && reqDecal._fpLastLRFootDistance < 0 && fCurFootDistance > reqDecal._fpLastLRFootDistance)) { bPlaceAFootprint = true; } reqDecal._fpbFootInMove[0] = reqDecal._fpbFootInMove[1] = true; reqDecal._fpbPlayerInMove = true; } else { if (reqDecal._fpbPlayerInMove) { reqDecal._fpLastFootsPos[0] = reqDecal._lrFoot[0].position; reqDecal._fpLastFootsPos[1] = reqDecal._lrFoot[1].position; reqDecal._fpbPlayerInMove = false; } float sqrDist = Vector3.Magnitude(reqDecal._lrFoot[reqDecal._curFoot].position - reqDecal._fpLastFootsPos[reqDecal._curFoot]); if (reqDecal._fpbFootInMove[reqDecal._curFoot]) { if (sqrDist < 0.02f) { reqDecal._fpbFootInMove[reqDecal._curFoot] = false; } reqDecal._fpLastFootsPos[reqDecal._curFoot] = reqDecal._lrFoot[reqDecal._curFoot].position; } else if (sqrDist > 0.04f) { reqDecal._fpbFootInMove[reqDecal._curFoot] = true; bPlaceAFootprint = true; } } if (bPlaceAFootprint || reqDecal._ctrlr.fallGround) { Transform curFoot = reqDecal._lrFoot[reqDecal._curFoot]; Ray ray = new Ray(curFoot.position + Vector3.up * reqDecal._rayLength * 0.5f, Vector3.down); RaycastHit hit; if (Physics.Raycast(ray, out hit, reqDecal._rayLength, (1 << _layerToFootprintTerra) | (1 << _layerToFootprintMetal))) { Vector3 pos = hit.point + (hit.normal * 0.02f); int hitLayer = hit.transform.gameObject.layer; if (hitLayer == _layerToFootprintTerra) { Vector3 vecFootprintDir = Quaternion.Euler(0, 90, 0) * curFoot.forward; vecFootprintDir.y = 0; int idxFoot = reqDecal._curFpIdx[reqDecal._curFoot]; Quaternion rot = Quaternion.FromToRotation(Vector3.up, hit.normal) * Quaternion.FromToRotation(Vector3.forward, vecFootprintDir); if (reqDecal._fpGoUpdates[reqDecal._curFoot, idxFoot] == null) { GameObject obj = MonoBehaviour.Instantiate(reqDecal._fpSeedGoLR, pos, rot) as GameObject; obj.transform.parent = reqDecal.FootPrintsParent; reqDecal._fpGoUpdates[reqDecal._curFoot, idxFoot] = obj.GetComponent <FootprintDecal>(); } else { reqDecal._fpGoUpdates[reqDecal._curFoot, idxFoot].Reset(pos, rot); } reqDecal._curFpIdx[reqDecal._curFoot] = (idxFoot + 1) % reqDecal._fpGoUpdates.GetLength(1); } //Sound effect if (bPlayerInMove || reqDecal._ctrlr.fallGround) { int soundID = 0; if (hitLayer == _layerToFootprintMetal) { if ((reqDecal._mmc == null || !reqDecal._mmc.GetMaskState(Pathea.PEActionMask.SwordAttack))) { int idx = UnityEngine.Random.Range(0, _nonTerClipIds.Length); soundID = _nonTerClipIds[idx]; if (_lastSoundID == soundID) { idx += UnityEngine.Random.Range(1, _nonTerClipIds.Length); if (idx >= _nonTerClipIds.Length) { idx -= _nonTerClipIds.Length; } soundID = _nonTerClipIds[idx]; } AudioManager.instance.Create(hit.point, soundID); _lastSoundID = soundID; } } else // _layerToFootprintTerr { int vType = 8; if (hitLayer == Pathea.Layer.VFVoxelTerrain) { VFVoxel groundVoxel = VFVoxelTerrain.self.Voxels.SafeRead((int)hit.point.x, (int)hit.point.y, (int)hit.point.z); vType = groundVoxel.Type; } NaturalRes res = NaturalResAsset.NaturalRes.GetTerrainResData(vType); if (res != null) { if (res.mGroundEffectID > 0) { Pathea.Effect.EffectBuilder.Instance.Register(res.mGroundEffectID, null, reqDecal.transform); } if (null != res.mGroundSoundIDs && res.mGroundSoundIDs.Length > 0 && (reqDecal._mmc == null || !reqDecal._mmc.GetMaskState(Pathea.PEActionMask.SwordAttack))) { if (res.mGroundSoundIDs.Length > 1) { int idx = UnityEngine.Random.Range(0, res.mGroundSoundIDs.Length); soundID = res.mGroundSoundIDs[idx]; if (_lastSoundID == soundID) { idx += UnityEngine.Random.Range(1, res.mGroundSoundIDs.Length); if (idx >= res.mGroundSoundIDs.Length) { idx -= res.mGroundSoundIDs.Length; } soundID = res.mGroundSoundIDs[idx]; } } else { soundID = res.mGroundSoundIDs[0]; } AudioManager.instance.Create(pos, soundID); _lastSoundID = soundID; } } } } } reqDecal._curFoot = (reqDecal._curFoot + 1) & 1; } reqDecal._fpLastLRFootDistance = fCurFootDistance; }
public bool UpdateOPTreeInfo() { mFindTreeInfo = null; if (null == trans) { return(false); } if (Vector3.Distance(trans.position, trans.position) > GatherMaxDis) { return(false); } List <GlobalTreeInfo> grassInfoList; if (null != LSubTerrainMgr.Instance) { grassInfoList = LSubTerrainMgr.Picking(trans.position, Vector3.forward, false, GatherMaxDis, 360f); } else if (null != RSubTerrainMgr.Instance) { grassInfoList = RSubTerrainMgr.Picking(trans.position, Vector3.forward, false, GatherMaxDis, 360f); } else { return(false); } for (int i = 0; i < grassInfoList.Count; i++) { NaturalRes resFind = NaturalResAsset.NaturalRes.GetTerrainResData(grassInfoList[i]._treeInfo.m_protoTypeIdx + 1000); if (null != resFind) { if (resFind.m_type == 10) { if (!PeCamera.cursorLocked) { if (null != LSubTerrainMgr.Instance) { Vector3 pos = grassInfoList[i].WorldPos; Bounds bound = new Bounds(); bound.SetMinMax(pos + grassInfoList[i]._treeInfo.m_heightScale * LSubTerrainMgr.Instance.GlobalPrototypeBounds[grassInfoList[i]._treeInfo.m_protoTypeIdx].min, pos + grassInfoList[i]._treeInfo.m_heightScale * LSubTerrainMgr.Instance.GlobalPrototypeBounds[grassInfoList[i]._treeInfo.m_protoTypeIdx].max); if (!bound.IntersectRay(PeCamera.mouseRay)) { continue; } } else if (null != RSubTerrainMgr.Instance) { Vector3 pos = grassInfoList[i]._treeInfo.m_pos; Bounds bound = new Bounds(); bound.SetMinMax(pos + grassInfoList[i]._treeInfo.m_heightScale * RSubTerrainMgr.Instance.GlobalPrototypeBounds[grassInfoList[i]._treeInfo.m_protoTypeIdx].min, pos + grassInfoList[i]._treeInfo.m_heightScale * RSubTerrainMgr.Instance.GlobalPrototypeBounds[grassInfoList[i]._treeInfo.m_protoTypeIdx].max); if (!bound.IntersectRay(PeCamera.mouseRay)) { continue; } } } mFindTreeInfo = grassInfoList[i]; break; } } } return(null != mFindTreeInfo); }