Example #1
0
    void RemoveTrees()
    {
        Vector3 dir       = m_LinkPos1 - m_LinkPos2;
        Vector3 normalDir = dir.normalized;

        RaycastHit[] hitTreeCols = Physics.RaycastAll(m_LinkPos2, normalDir, dir.magnitude, 1 << Pathea.Layer.NearTreePhysics, QueryTriggerInteraction.Ignore);
        for (int i = 0; i < hitTreeCols.Length; ++i)
        {
            GlobalTreeInfo gTreeinfo = PETools.PEUtil.GetTreeinfo(hitTreeCols[i].collider);
            if (null != gTreeinfo)
            {
                DigTerrainManager.RemoveTree(gTreeinfo);
            }
        }
    }
Example #2
0
    protected void RPC_SKFellTree(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        /*int typeIndex = */ stream.Read <int> ();
        Vector3 pos = stream.Read <Vector3> ();

        /*float maxHP = */ stream.Read <float> ();
        float hp = stream.Read <float> ();

        TreeInfo tree = null;        // = RSubTerrainMgr.TreesAtPosF(pos);

        if (null != LSubTerrainMgr.Instance)
        {
            int x = Mathf.FloorToInt(pos.x);
            int y = Mathf.FloorToInt(pos.y);
            int z = Mathf.FloorToInt(pos.z);
            List <GlobalTreeInfo> tree_list = LSubTerrainMgr.Picking(new IntVector3(x, y, z), true);
            if (tree_list.Count > 0)
            {
                foreach (var iter in tree_list)
                {
                    if (hp <= 0)
                    {
                        PeEntity entity   = EntityMgr.Instance.Get(Id);
                        SkEntity skEntity = null == entity ? null : entity.skEntity;
                        SkEntitySubTerrain.Instance.OnTreeCutDown(skEntity, iter);
                        DigTerrainManager.RemoveTree(iter);
                        if (IsOwner)
                        {
                            SkEntitySubTerrain.Instance.SetTreeHp(iter.WorldPos, hp);
                        }
                    }
                    else
                    {
                        if (IsOwner)
                        {
                            SkEntitySubTerrain.Instance.SetTreeHp(iter.WorldPos, hp);
                        }
                    }
                }
            }
        }
        else if (null != RSubTerrainMgr.Instance)
        {
            RSubTerrSL.AddDeletedTree(pos);
            tree = RSubTerrainMgr.TreesAtPosF(pos);
            if (null != tree)
            {
                GlobalTreeInfo gTree = new GlobalTreeInfo(-1, tree);
                if (hp <= 0)
                {
                    PeEntity entity   = EntityMgr.Instance.Get(Id);
                    SkEntity skEntity = null == entity ? null : entity.skEntity;
                    SkEntitySubTerrain.Instance.OnTreeCutDown(skEntity, gTree);
                    DigTerrainManager.RemoveTree(gTree);
                    if (IsOwner)
                    {
                        SkEntitySubTerrain.Instance.SetTreeHp(gTree.WorldPos, hp);
                    }
                }
                else
                {
                    if (IsOwner)
                    {
                        SkEntitySubTerrain.Instance.SetTreeHp(gTree.WorldPos, hp);
                    }
                }
            }
        }
    }
    private void onAlterAttribs(int idx, float oldValue, float newValue)
    {
//		if(_targetTree == null)	return;
//		Debug.Log("Cutting a tree........");

        /* when the tree's hp has been cut to zero
         * if (null != LSubTerrainMgr.Instance)
         * {
         *      LSubTerrainMgr.DeleteTree(mGroundItem);
         *      LSubTerrainMgr.RefreshAllLayerTerrains();
         * }
         * else if (null != RSubTerrainMgr.Instance)
         * {
         *      RSubTerrainMgr.DeleteTree(mGroundItem._treeInfo);
         *      RSubTerrainMgr.RefreshAllLayerTerrains();
         * }
         */

        if (idx != 2)
        {
            return;
        }

        float damage         = _attribs.sums[0];
        float resourceBonus  = _attribs.sums[1];
        bool  returnResource = _attribs.sums[2] > 0.0f;

        SkEntity caster = GetCasterToModAttrib(idx);

        if (null != caster)
        {
            ISkSubTerrain subTerrain = caster as ISkSubTerrain;
            if (null != subTerrain && null != subTerrain.treeInfo)
            {
                treeHPInfos[subTerrain.treeInfo.WorldPos] = DigTerrainManager.Fell(subTerrain.treeInfo, damage, GetTreeHP(subTerrain.treeInfo.WorldPos));
                if (GameConfig.IsMultiMode)
                {
                    caster.SendFellTree(subTerrain.treeInfo._treeInfo.m_protoTypeIdx, subTerrain.treeInfo.WorldPos, subTerrain.treeInfo._treeInfo.m_heightScale, subTerrain.treeInfo._treeInfo.m_widthScale);
                }
                else
                {
                    if (treeHPInfos[subTerrain.treeInfo.WorldPos] <= 0)
                    {
                        OnTreeCutDown(caster, subTerrain.treeInfo);
                        DigTerrainManager.RemoveTree(subTerrain.treeInfo);
                        if (returnResource)
                        {
                            bool bGetSpItems = false;
                            if (caster is SkAliveEntity)
                            {
                                SkAliveEntity alive = (SkAliveEntity)caster;
                                if (alive.Entity.proto == EEntityProto.Player)
                                {
                                    SkillTreeUnitMgr mgr = alive.Entity.GetCmpt <SkillTreeUnitMgr>();
                                    bGetSpItems = mgr.CheckMinerGetRare();
                                }
                            }
                            Dictionary <int, int> itemGet = DigTerrainManager.GetTreeResouce(subTerrain.treeInfo, resourceBonus, bGetSpItems);
                            if (itemGet.Count > 0)
                            {
                                List <int> itemsArray = new List <int>(itemGet.Count * 2);
                                foreach (int intemID in itemGet.Keys)
                                {
                                    itemsArray.Add(intemID);
                                    itemsArray.Add(itemGet[intemID]);
                                }
                                GetSpecialItem.PlantItemAdd(ref itemsArray);  //植物特殊道具添加
                                caster._attribs.pack += itemsArray.ToArray();
                            }
                        }
                    }
                }
            }
        }
    }