Exemplo n.º 1
0
        public override UnitPosition Select(IEventArgs args)
        {
            UnitPosition up       = pos.Select(args);
            Vector3      position = UnityPositionUtil.ToVector3(up);

            RaycastHit hitInfo;

            if (SingletonManager.Get <MapConfigManager>().InWater(position))
            {
                Ray  ray = new Ray(position, Vector3.up);
                bool hit = Physics.Raycast(ray, out hitInfo, 10000, UnityLayerManager.GetLayerMask(EUnityLayerName.WaterTrigger));
                if (hit)
                {
                    return(UnityPositionUtil.FromVector(hitInfo.point - new Vector3(0, waterDelta, 0)));
                }
            }
            else
            {
                Ray  ray = new Ray(position, Vector3.down);
                bool hit = Physics.Raycast(ray, out hitInfo, 10000, UnityLayers.SceneCollidableLayerMask | UnityLayerManager.GetLayerMask(EUnityLayerName.WaterTrigger));
                if (hit)
                {
                    if (hitInfo.collider.transform.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.WaterTrigger))
                    {
                        return(UnityPositionUtil.FromVector(hitInfo.point - new Vector3(0, waterDelta, 0)));
                    }
                    else
                    {
                        return(UnityPositionUtil.FromVector(hitInfo.point));
                    }
                }
            }
            return(up);
        }
Exemplo n.º 2
0
 protected override void BuildMessage(IEventArgs args)
 {
     builder.Key = FreeMessageConstant.PlaySound;
     if (null == pos)
     {
         if (play)
         {
             builder.Ks.Add(2);
             builder.Ins.Add(sound);
             builder.Bs.Add(self);
         }
         else
         {
         }
     }
     else
     {
         UnitPosition up = pos.Select(args);
         if (up != null)
         {
             builder.Ks.Add(3);
             builder.Fs.Add(up.GetX());
             builder.Fs.Add(up.GetY());
             builder.Fs.Add(up.GetZ());
             builder.Ins.Add(sound);
         }
     }
 }
Exemplo n.º 3
0
        public override UnitPosition Select(IEventArgs args)
        {
            UnitPosition up = pos.Select(args);

            Vector3 fromV = UnityPositionUtil.ToVector3(up);

            Vector3 toV = new Vector3(up.GetX(), -10000, up.GetZ());

            Ray r = new Ray(fromV, new Vector3(toV.x - fromV.x, toV.y - fromV.y, toV.z - fromV.z));

            RaycastHit hitInfo;
            bool       hited = Physics.Raycast(r, out hitInfo);

            if (hited)
            {
                if (SingletonManager.Get <MapConfigManager>().InWater(new Vector3(hitInfo.point.x,
                                                                                  hitInfo.point.y - 0.1f, hitInfo.point.z)))
                {
                    hitInfo.point = new Vector3(fromV.x, hitInfo.point.y - waterDelta, fromV.z);
                }

                //Debug.LogFormat("hit {0},{1},{2}", hitInfo.point.x, hitInfo.point.y, hitInfo.point.z);

                return(UnityPositionUtil.FromVector(hitInfo.point));
            }

            return(up);
        }
Exemplo n.º 4
0
        public override void DoAction(IEventArgs args)
        {
            int realType = args.GetInt(type);
            int dis      = args.GetInt(distance);

            int i = 1;

            UnitPosition up     = pos.Select(args);
            Vector3      target = new Vector3(up.GetX(), up.GetY(), up.GetZ());

            foreach (MapConfigPoints.ID_Point p in FreeMapPosition.GetPositions(args.GameContext.session.commonSession.RoomInfo.MapId).IDPints)
            {
                if (p.ID == realType)
                {
                    foreach (MapConfigPoints.SavedPointData v in p.points)
                    {
                        if (IsNear(v.pos, target, dis))
                        {
                            TriggerArgs ta = new TriggerArgs();
                            ta.AddPara(new FloatPara("x", v.pos.x));
                            ta.AddPara(new FloatPara("y", v.pos.y));
                            ta.AddPara(new FloatPara("z", v.pos.z));
                            ta.AddPara(new FloatPara("index", i++));

                            args.Act(action, ta);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public override bool InRectange(FreeUIUtil.Rectangle rec, IEventArgs args)
        {
            if (pos == null || change)
            {
                pos = selector.Select(args);
            }
            int   px = (int)(pos.GetX());
            int   py = (int)(pos.GetY());
            float r  = 0f;

            try
            {
                r = float.Parse(radius);
            }
            catch (Exception)
            {
                r = FreeUtil.ReplaceFloat(radius, args);
            }
            float x1 = rec.x - r;
            float x2 = rec.x + rec.width + r;
            float y1 = rec.y - r;
            float y2 = rec.y + rec.height + r;

            // 圆心在矩形的加上圆半径的范围内
            return(px >= x1 && px <= x2 && py >= y1 && py <= y2);
        }
Exemplo n.º 6
0
        public override bool IsIn(IEventArgs args, UnitPosition entity)
        {
            bool isIn = false;

            foreach (MapConfigPoints.ID_Point p in MapConfigPoints.current.IDPints)
            {
                if (p.ID == FreeUtil.ReplaceInt(type, args))
                {
                    foreach (MapConfigPoints.SavedPointData spd in p.points)
                    {
                        float dx = MyMath.Abs(entity.GetX() - spd.pos.x);
                        float dz = MyMath.Abs(entity.GetZ() - spd.pos.z);
                        float dy = MyMath.Abs(entity.GetY() - spd.pos.y);
                        if (dx * dx + dz * dz <= spd.cylinderVolR * spd.cylinderVolR && dy <= spd.cylinderVolH)
                        {
                            isIn = true;
                            break;
                        }
                    }

                    if (isIn)
                    {
                        break;
                    }
                }
            }

            if (useOut)
            {
                return(!isIn);
            }

            return(isIn);
        }
Exemplo n.º 7
0
 public override UnitPosition GetCenter(IEventArgs args)
 {
     if (pos == null || change)
     {
         pos = selector.Select(args);
     }
     return(pos);
 }
Exemplo n.º 8
0
        public override string GetStyle(IEventArgs args, string key)
        {
            UnitPosition fromUp = from.Select(args);
            UnitPosition toUp   = to.Select(args);

            return(fromUp.GetX() + "_" + fromUp.GetY() + "_" + fromUp.GetZ() + SPLITER + toUp.GetX() + "_" + toUp.GetY() + "_" + toUp.GetZ() + SPLITER + FreeUtil.ReplaceVar(name, args) + SPLITER + FreeUtil.ReplaceFloat(scale, args) + SPLITER + FreeUtil.
                   ReplaceFloat(adjust, args));
        }
Exemplo n.º 9
0
        public static UnitPosition GetPlayerPosition(PlayerEntity player)
        {
            UnitPosition tempPosition = new UnitPosition();

            SetPlayerToUnitPosition(player, tempPosition);

            return(tempPosition);
        }
Exemplo n.º 10
0
 public static void SetPlayerToUnitPosition(PlayerEntity player, UnitPosition up)
 {
     up.SetX(player.position.Value.x);
     up.SetY(player.position.Value.y);
     up.SetZ(player.position.Value.z);
     up.SetYaw(player.orientation.Yaw);
     up.SetPitch(player.orientation.Pitch);
 }
Exemplo n.º 11
0
        public static UnitPosition GetEntityPosition(PositionComponent entity)
        {
            UnitPosition tempPosition = new UnitPosition();

            SetEntityToUnitPosition(entity, tempPosition);

            return(tempPosition);
        }
Exemplo n.º 12
0
    public void addUnit(Unit toAdd, int position)
    {
        UnitPosition u = new UnitPosition();

        u.position = position;
        u.unit     = toAdd;
        unitList.Add(u);
    }
Exemplo n.º 13
0
        public override UnitPosition Select(IEventArgs args)
        {
            IniCon();

            UnitPosition up = new UnitPosition();

            FreeRuleEventArgs fr = (FreeRuleEventArgs)args;

            if (!string.IsNullOrEmpty(player))
            {
                object obj = fr.GetEntity(player);
                if (obj != null)
                {
                    if (obj is PlayerEntity)
                    {
                        PlayerEntity playerEntity = (PlayerEntity)obj;
                        fr.TempUse("current", (FreeData)playerEntity.freeData.FreeData);

                        UnityPositionUtil.SetPlayerToUnitPosition(playerEntity, up);
                        if (fromEye)
                        {
                            up.SetY(up.GetY() + 1.7f);
                        }

                        fr.Resume("current");
                    }

                    if (obj is FreeMoveEntity)
                    {
                        FreeMoveEntity playerEntity = (FreeMoveEntity)obj;
                        fr.TempUse("current", (FreeEntityData)playerEntity.freeData.FreeData);

                        UnityPositionUtil.SetEntityToUnitPosition(playerEntity.position, up);

                        fr.Resume("current");
                    }
                }
            }
            else if (!string.IsNullOrEmpty(condition))
            {
                if (con == null || con.Meet(args))
                {
                    foreach (PlayerEntity unit in args.GameContext.player.GetInitializedPlayerEntities())
                    {
                        if (unit.hasFreeData)
                        {
                            fr.TempUse("current", (FreeData)unit.freeData.FreeData);

                            UnityPositionUtil.SetPlayerToUnitPosition(unit, up);

                            fr.Resume("current");
                        }
                    }
                }
            }

            return(GetPosition(args, up, FreeUtil.ReplaceFloat(angle, args) + up.GetYaw()));
        }
Exemplo n.º 14
0
        private IPosSelector GetPos(UnitPosition up)
        {
            PosAssignSelector pas = new PosAssignSelector();

            pas.SetX(up.GetX().ToString());
            pas.SetY(up.GetY().ToString());
            pas.SetZ(up.GetZ().ToString());
            return(pas);
        }
Exemplo n.º 15
0
        public override bool Frame(FreeRuleEventArgs args, FreeMoveEntity entity, int interval)
        {
            if (dynamic)
            {
                tempPosition = targetPos.Select(args);
            }

            float speedMeter = GetSpeed(args, entity).GetSpeed(args, interval);

            float dis = speedMeter * (float)interval / 1000f;

            if (tempPosition.Distance(GetEntityPosition(entity)) < dis)
            {
                UnityPositionUtil.SetUnitPositionToEntity(entity.position, tempPosition);

                if (action != null && !firstTime)
                {
                    args.TempUsePara(new FloatPara("x", entity.position.Value.x));
                    args.TempUsePara(new FloatPara("y", entity.position.Value.y));
                    args.TempUsePara(new FloatPara("z", entity.position.Value.z));

                    action.Act(args);

                    args.ResumePara("x");
                    args.ResumePara("y");
                    args.ResumePara("z");

                    firstTime = true;
                }

                if (!stayTarget)
                {
                    return(true);
                }
            }
            else
            {
                Vector3      from = entity.position.Value;
                UnitPosition ep   = GetEntityPosition(entity);
                UnityPositionUtil.Move(ep, tempPosition, dis);

                entity.position.Value = new Vector3(ep.GetX(), ep.GetY(), ep.GetZ());

                if (hitType > 0)
                {
                    bool hit = CheckHit(args, (FreeEntityData)entity.freeData.FreeData, from, entity.position.Value, dis);

                    if (hit)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 16
0
        public virtual void Start(FreeRuleEventArgs args, FreeMoveEntity entity)
        {
            startTime = args.Rule.ServerTime;

            UnitPosition up = startPos.Select(args);

            entity.position.Value = new Vector3(up.GetX(), up.GetY(), up.GetZ());

            StartMove(args, entity);
        }
Exemplo n.º 17
0
        public static UnitPosition FromVector(Vector3 v)
        {
            UnitPosition tempPosition = new UnitPosition();

            tempPosition.SetX(v.x);
            tempPosition.SetY(v.y);
            tempPosition.SetZ(v.z);

            return(tempPosition);
        }
Exemplo n.º 18
0
        public override void DoAction(IEventArgs args)
        {
            UnitPosition up = pos.Select(args);

            Contexts con = args.GameContext;

            VehicleEntityUtility.CreateNewVehicle(con.vehicle, FreeUtil.ReplaceInt(carId, args),
                                                  con.session.commonSession.EntityIdGenerator.GetNextEntityId(),
                                                  map.position.UnityPositionUtil.ToVector3(up));
        }
Exemplo n.º 19
0
        public override void StartMove(FreeRuleEventArgs args, FreeMoveEntity entity)
        {
            tempPosition = targetPos.Select(args);
            if (!string.IsNullOrEmpty(useTime))
            {
                realTime = FreeUtil.ReplaceFloat(useTime, args);
            }

            UnityPositionUtil.SetUnitPositionToEntity(entity.position, startPos.Select(args));
        }
Exemplo n.º 20
0
        public virtual UnitPosition Select(IEventArgs args)
        {
            UnitPosition up = pos.Select(args);

            if (up != null)
            {
                Adjust(up, args);
            }
            return(up);
        }
Exemplo n.º 21
0
        public override UnitPosition Select(IEventArgs args)
        {
            UnitPosition up = new UnitPosition();

            up.SetX(FreeUtil.ReplaceFloat(x, args));
            up.SetY(FreeUtil.ReplaceFloat(y, args));
            up.SetZ(FreeUtil.ReplaceFloat(z, args));
            up.SetYaw(FreeUtil.ReplaceFloat(yaw, args));
            up.SetPitch(FreeUtil.ReplaceFloat(pitch, args));
            return(up);
        }
Exemplo n.º 22
0
        public override UnitPosition Select(IEventArgs args)
        {
            UnitPosition up = pos.Select(args);

            if (up != null)
            {
                return(GetPosition(args, up, FreeUtil.ReplaceFloat(angle, args)));
            }

            return(null);
        }
Exemplo n.º 23
0
        public override bool IsIn(IEventArgs args, UnitPosition entity)
        {
            if (pos == null || change)
            {
                pos = selector.Select(args);
            }
            float r = 0f;

            try
            {
                r = float.Parse(radius);
            }
            catch (Exception)
            {
                r = FreeUtil.ReplaceFloat(radius, args);
            }

            double dx = MyMath.Abs(entity.GetX() - pos.GetX());

            if (dx > r)
            {
                if (useOut)
                {
                    return(true);
                }
                return(false);
            }
            double dz = MyMath.Abs(entity.GetZ() - pos.GetZ());

            if (dz > r)
            {
                if (useOut)
                {
                    return(true);
                }
                return(false);
            }
            double dy     = MyMath.Abs(entity.GetY() - pos.GetY());
            float  zrange = FreeUtil.ReplaceFloat(zRange, args);

            if (zrange <= 0)
            {
                zrange = 170;
            }

            bool isIn = (dx * dx + dz * dz) <= r * r && (dy < zrange);

            if (useOut)
            {
                return(!isIn);
            }
            return(isIn);
        }
Exemplo n.º 24
0
 public override void OnNext(UnitInfo info)
 {
     switch (info.id)
     {
         case UnitDefId.Pacman:
             pacmanPosition = info.position;
             break;
         case UnitDefId.Blinky:
             blinkyPosition = info.position;
             break;
     }
 }
Exemplo n.º 25
0
 public virtual string GetXyz(IEventArgs args)
 {
     if (selector != null)
     {
         UnitPosition up = selector.Select(args);
         if (up != null)
         {
             return(up.GetX() + "," + up.GetY() + "," + up.GetZ());
         }
     }
     return(string.Empty);
 }
Exemplo n.º 26
0
        public override UnitPosition Select(IEventArgs args)
        {
            UnitPosition up = new UnitPosition();

            up.SetX(FreeUtil.ReplaceFloat(x, args));
            up.SetY(FreeUtil.ReplaceFloat(y, args));
            up.SetZ(FreeUtil.ReplaceFloat(z, args));
            up.SetYaw(FreeUtil.ReplaceFloat(yaw, args));
            up.SetPitch(FreeUtil.ReplaceFloat(pitch, args));
            up.SetInvalid(FreeUtil.ReplaceBool(invalid, args));
            up.SetRandomindex(FreeUtil.ReplaceInt(randomindex, args));
            return(up);
        }
Exemplo n.º 27
0
        protected override void BuildMessage(IEventArgs args)
        {
            this.scope = "4";

            builder.Key = FreeMessageConstant.PoisonCircle;
            UnitPosition from = pos.Select(args);

            builder.Ks.Add(1);
            builder.Fs.Add(from.GetX());
            builder.Fs.Add(from.GetZ());

            builder.Ins.Add(FreeUtil.ReplaceInt(radius, args));
        }
Exemplo n.º 28
0
        public void UpdateUnitPosition(UnitPosition unitPosition)
        {
            bool created;
            var  unit = GetOrInstantiate(unitPosition.Id, out created);

            if (unit.Movement)
            {
                unit.Movement.Moving = unitPosition.Moving;
                unit.Movement.SetPosition(
                    new Vector3(unitPosition.X, 0, unitPosition.Y),
                    interpolate: !created);
            }
        }
Exemplo n.º 29
0
        // 一个位置向另外一个位置移动一段距离后的点位置, 修改from的值
        public static void Move(UnitPosition from, UnitPosition target, float dis)
        {
            Vector3 v = new Vector3(target.GetX() - from.GetX(), target.GetY() - from.GetY(), target.GetZ() - from.GetZ());

            if (v.magnitude != 0)
            {
                float scale = dis / v.magnitude;

                from.SetX(from.GetX() + v.x * scale);
                from.SetY(from.GetY() + v.y * scale);
                from.SetZ(from.GetZ() + v.z * scale);
            }
        }
Exemplo n.º 30
0
        public bool Meet(IEventArgs args)
        {
            UnitPosition up = pos.Select(args);

            if (useOut)
            {
                return(!region.In(args, up));
            }
            else
            {
                return(region.In(args, up));
            }
        }
Exemplo n.º 31
0
        protected UnitPosition GetEntityPosition(FreeMoveEntity entity)
        {
            if (_entityPosition == null)
            {
                _entityPosition = new UnitPosition();
            }

            _entityPosition.SetX(entity.position.Value.x);
            _entityPosition.SetY(entity.position.Value.y);
            _entityPosition.SetZ(entity.position.Value.z);

            return(_entityPosition);
        }
Exemplo n.º 32
0
        public override UnitPosition GetNextMovePoint()
        {
            CurrentPosition = nextPosition;

            CollectDot();
            CollectBonus();

            CheckIsPortMovement();

            var point = CurrentPosition.point;
            var direction = CurrentPosition.direction;

            if (maze.StepIsPossible(point, direction))
            {
                nextPosition = new UnitPosition(point + steps[direction], direction);
                return nextPosition;
            }

            return CurrentPosition;
        }
Exemplo n.º 33
0
 public List<UnitPosition> GetDeployment()
 {
     List<UnitPosition> output = new List<UnitPosition>();
     foreach (var unit in Units)
     {
         if (!unit.Deployed)
             continue;
         UnitPosition unitPosition = new UnitPosition(unit.Id, unit.Hex.Position);
         output.Add(unitPosition);
     }
     return output;
 }
Exemplo n.º 34
0
 public void SetCurrentPosition(UnitPosition position)
 {
     nextPosition = position;
     CurrentPosition = nextPosition;
 }