Example #1
0
        public ShellViewModel()
        {
            // Init a probe
            probe = new ProbeModel
            {
                TotalElements       = 64,
                UsedElementsPerBeam = 4,
                Frequency           = 5,
                Pitch = 1,
            };

            // Init a gate
            gate = new GateModel
            {
                Start     = 10,
                Length    = 50,
                Threshold = 20,
            };
            GateStart     = gate.Start.ToString();
            GateLength    = gate.Length.ToString();
            GateThreshold = gate.Threshold.ToString();

            // Init Ascan
            InitAscan();
            PlotGate();

            // Init Cscan
            InitCscan();
        }
Example #2
0
        public void Init(GameModel gameModel)
        {
            GateModel gateModel = (GateModel)gameModel;

            _timeOut            = gateModel.TimeOut;
            _animatorController = gameObject.GetComponent <Animator>();
        }
        public bool AddGate(GateModel gate)
        {
            List <GateModel> gateData = GatesDataInitialization.GatesData();

            gateData.Add(gate);
            return(true);
        }
Example #4
0
        /// <summary>
        ///     Return gate offset position when moving
        /// </summary>
        /// <param name="currentGate"></param>
        /// <param name="currentPosition"></param>
        /// <param name="distance">distance from current position</param>
        /// <param name="openingMotion">direction from current position</param>
        private static Vector3 GetGateOffsetPosition(GateModel currentGate, Vector3 currentPosition, float distance,
                                                     GateMovement openingMotion)
        {
            try {
                if (currentGate == null)
                {
                    return(Vector3.One);
                }

                var heading = currentGate.Heading + 180f;

                var cosx = Math.Cos(heading * (Math.PI / 180f));
                var siny = Math.Sin(heading * (Math.PI / 180f));

                var deltax = distance * cosx * (int)openingMotion;
                var deltay = distance * siny * (int)openingMotion;

                var newX = (float)(currentPosition.X + deltax);
                var newY = (float)(currentPosition.Y + deltay);

                return(new Vector3(newX, newY, currentPosition.Z));
            }
            catch (Exception ex) {
                Log.Error(ex);
            }

            return(Vector3.One);
        }
Example #5
0
        /// <summary>
        ///     Search for nearby gates, update them if they're close, set current game variables if player within access range
        /// </summary>
        /// <param name="playerPos"></param>
        private static void SearchForNearbyGates(Vector3 playerPos)
        {
            try {
                var props = new ObjectList();
                foreach (var handle in props)
                {
                    var entity = Entity.FromHandle(handle);
                    if (entity == null || !entity.Exists())
                    {
                        continue;
                    }

                    var entityHash = entity.Model.Hash;
                    foreach (var gate in LockableGates)
                    {
                        if (entityHash != gate.Value.Hash || playerPos.DistanceToSquared2D(gate.Value.ClosedPosition) > 3000f)
                        {
                            continue;
                        }

                        var propList = Props.FindProps(gate.Value.ModelName, 3000f);
                        var gateProp = propList.OrderBy(p => Entity.FromHandle(p)?.Position.DistanceToSquared2D(playerPos))
                                       .FirstOrDefault();

                        entity = Entity.FromHandle(gateProp);
                        if (entity == null || !entity.Exists())
                        {
                            continue;
                        }

                        if (playerPos.DistanceToSquared2D(gate.Value.ClosedPosition) > 800f)
                        {
                            if (DateTime.Now.CompareTo(gate.Value.LastUpdate) < 0)
                            {
                                continue;
                            }

                            gate.Value.LastUpdate = DateTime.Now.AddSeconds(5);
                            SetGatePosition(entity, gate.Value);
                            continue;
                        }

                        _gateEntity    = entity;
                        _currentGate   = gate.Value;
                        _currentGateId = gate.Key;
                        var offSetPosition = GetGateOffsetPosition(_currentGate, _currentGate.ClosedPosition, _currentGate.GateLength,
                                                                   _currentGate.OpeningMovement);
                        _gateTarget          = _currentGate.IsLocked ? _currentGate.ClosedPosition : offSetPosition;
                        _gateEntity.Position = _gateTarget;

                        break;
                    }
                }
            }
            catch (Exception ex) {
                Log.Error(ex);
            }
        }
Example #6
0
 public static GateContractsModel GetContractModel(GateModel model)
 {
     return(new GateContractsModel()
     {
         Id = model.Id,
         Gate = model.Gate,
         Status = model.Status
     });
 }
        public LocationSiteModel BuildLocation(LocationsModel locationsModel)
        {
            var locations  = locationsModel.Value;
            var warehouses = locations.GroupBy(x => x.Warehouse)
                             .Select(loc => new { Name = loc.Key, Items = loc.ToList() });

            var location = new LocationSiteModel();

            location.Warehouses = new List <WarehouseModel>();

            foreach (var warehouse in warehouses)
            {
                var warehouseLocal = new WarehouseModel();
                warehouseLocal.Name  = warehouse.Name;
                warehouseLocal.Gates = new List <GateModel>();

                var gates = warehouse.Items.GroupBy(x => x.Gate)
                            .Select(g => new { Name = g.Key, Items = g.ToList() });

                foreach (var gate in gates)
                {
                    var gateLocal = new GateModel {
                        Name = gate.Name
                    };
                    gateLocal.Rows = new List <RowModel>();

                    var rows = gate.Items.GroupBy(x => x.Row)
                               .Select(r => new { Name = r.Key, Items = r.ToList() });

                    foreach (var row in rows)
                    {
                        var rowLocal = new RowModel
                        {
                            Name = row.Name
                        };

                        var positions = row.Items.GroupBy(x => x.Position)
                                        .Select(p => new PositionModel {
                            Name = p.Key
                        });

                        rowLocal.Positions = new List <PositionModel>(positions);
                        gateLocal.Rows.Add(rowLocal);
                    }
                    warehouseLocal.Gates.Add(gateLocal);
                }
                location.Warehouses.Add(warehouseLocal);
            }

            return(location);
        }
Example #8
0
        /// <summary>
        ///     Control gate movement tick
        /// </summary>
        private static async Task GateMovementTick()
        {
            try {
                if (!Session.HasJoinedRP)
                {
                    await BaseScript.Delay(5000);

                    return;
                }

                if (_gateEntity == null)
                {
                    _currentGate     = null;
                    _gatePositionSet = false;

                    await BaseScript.Delay(1000);

                    return;
                }

                if (!_gatePositionSet)
                {
                    SetGatePosition(_gateEntity, _currentGate);
                    _gatePositionSet = true;
                }

                var isGateAtTargetPostiion = _gateEntity.Position == _gateTarget;
                if (isGateAtTargetPostiion)
                {
                    await BaseScript.Delay(500);

                    return;
                }

                ClampGatePosition();

                if (_gateEntity.Position.DistanceToSquared2D(_gateTarget) >= 0.01)
                {
                    await MoveGateTowardsTarget();

                    PeriodicVehicleCheck();
                }
                else
                {
                    _gateEntity.Position = _gateTarget;
                }
            }
            catch (Exception ex) {
                Log.Error(ex);
            }
        }
        public GateContractsModel GetById(long gateId)
        {
            if (gateId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(gateId));
            }

            using (_context)
            {
                this._gate = this._context.Gate.FirstOrDefault(x => x.Id == gateId);
            }

            return(this._gate == null ? null : ModelConverterHelper.GetContractModel(this._gate));
        }
        public bool Save(GateContractsModel gate)
        {
            if (gate == null)
            {
                throw new ArgumentNullException(nameof(gate));
            }

            using (_context)
            {
                this._gate = this._context.Gate.FirstOrDefault(x => x.Id == gate.Id);
                this._gate = ModelConverterHelper.GetModelFromContract(gate);
                this._context.SaveChanges();
            }

            return(true);
        }
        public bool Add(GateContractsModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            using (_context)
            {
                this._gate = ModelConverterHelper.GetModelFromContract(model);
                this._context.Gate.Add(this._gate);
                this._context.SaveChanges();
            }

            return(true);
        }
Example #12
0
        /// <summary>
        ///     Return whether or not the player has duty access for the gate
        /// </summary>
        /// <param name="gate"></param>
        private static bool PlayerHasPermission(GateModel gate)
        {
            try {
                foreach (var permission in gate.Permissions)
                {
                    if (Business.Business.HasPermission(permission))
                    {
                        return(true);
                    }
                }
            }
            catch (Exception ex) {
                Log.Error(ex);
            }

            return(false);
        }
Example #13
0
 /// <summary>
 ///     Set the gate position, freeze it, and record collisions
 /// </summary>
 /// <param name="gateEntity"></param>
 /// <param name="currGate">current gate model</param>
 private static void SetGatePosition(Entity gateEntity, GateModel currGate)
 {
     try {
         if (gateEntity == null)
         {
             return;
         }
         if (currGate != null)
         {
             if (!currGate.IsLocked)
             {
                 gateEntity.Position = GetGateOffsetPosition(currGate, currGate.ClosedPosition, currGate.GateLength,
                                                             currGate.OpeningMovement);
             }
         }
         gateEntity.IsPositionFrozen      = true;
         gateEntity.IsRecordingCollisions = true;
     }
     catch (Exception ex) {
         Log.Error(ex);
     }
 }
        public bool Remove(long id)
        {
            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(id));
            }

            using (_context)
            {
                this._gate = this._context.Gate.FirstOrDefault(x => x.Id == id);

                if (this._gate == null)
                {
                    return(false);
                }

                this._context.Gate.Remove(this._gate);
                this._context.SaveChanges();
            }

            return(true);
        }
Example #15
0
 /// <summary>
 /// change the direction of the gate
 /// </summary>
 public void ChangeGateDirection(GateModel gate)
 {
     gate.GateOpenDirection = !gate.GateOpenDirection;
 }
Example #16
0
    public void Save()
    {
        UIManager.instance.ShowSavingIcon();
        PlayerModel player = new PlayerModel(new VectorModel(GameManager.instance.player.transform.position), new VectorModel(GameManager.instance.player.transform.eulerAngles), GameManager.instance.coinCount, GameManager.instance.player.playerValues.health, GameManager.instance.player.playerValues.maxHealth);

        localSaveModel = new SaveModel(LevelManager.instance.LevelNumber, new VectorModel(LevelManager.instance.currentCheckpoint.position), LevelManager.instance.hasGateKey, player);
        //Moveable objects
        foreach (GameObject go in MovableObjects.Values)
        {
            ObjectModel model = new ObjectModel(GetId(go), go.activeSelf, new VectorModel(go.transform.position), new VectorModel(go.transform.eulerAngles));
            localSaveModel.MovableObjects.Add(model);
            //Debug.Log(model.Id + " " + model.IsDisabled + " " + model.Position + " " + model.Rotation);
        }

        foreach (GameObject go in Haybales.Values)
        {
            ObjectModel model = new ObjectModel(GetId(go), go.activeSelf, new VectorModel(go.transform.position), new VectorModel(go.transform.eulerAngles));
            localSaveModel.Haybales.Add(model);
        }

        foreach (GameObject go in Checkpoints.Values)
        {
            ObjectModel model = new ObjectModel(GetId(go), go.activeSelf, new VectorModel(go.transform.position), new VectorModel(go.transform.eulerAngles));
            localSaveModel.Checkpoints.Add(model);
        }

        foreach (FallingObject fo in FallingObjects.Values)
        {
            FallingObjectModel model = new FallingObjectModel(GetId(fo.gameObject), fo.gameObject.activeSelf, new VectorModel(fo.transform.position), new VectorModel(fo.transform.eulerAngles), fo.HasFallen);
            localSaveModel.FallingObjects.Add(model);
        }

        foreach (Breakable to in TrapObjects.Values)
        {
            FallingObjectModel model = new FallingObjectModel(GetId(to.gameObject), to.gameObject.activeSelf, new VectorModel(to.transform.position), new VectorModel(to.transform.eulerAngles), to.Broke);
            localSaveModel.TrapObjects.Add(model);
        }

        foreach (Peasant en in Enemies.Values)
        {
            EnemyModel model = new EnemyModel(GetId(en.gameObject), en.gameObject.activeSelf, new VectorModel(en.transform.position), new VectorModel(en.transform.eulerAngles), en.CurrentToughness, en.IsStunned);
            localSaveModel.Enemies.Add(model);
        }

        foreach (GateScript gs in Gates.Values)
        {
            GateModel model = new GateModel(GetId(gs.gameObject), gs.gameObject.activeSelf, new VectorModel(gs.transform.position), new VectorModel(gs.transform.eulerAngles), gs.IsOpened);
            localSaveModel.Gates.Add(model);
        }

        foreach (Dashable ds in Dashables.Values)
        {
            ObjectModel model = new ObjectModel(GetId(ds.gameObject), ds.gameObject.activeSelf, new VectorModel(ds.gameObject.transform.position), new VectorModel(ds.gameObject.transform.eulerAngles));
            localSaveModel.Dashables.Add(model);
        }

        foreach (CoinPickup co in Coins.Values)
        {
            ObjectModel model = new ObjectModel(GetId(co.gameObject), co.gameObject.activeSelf, new VectorModel(co.gameObject.transform.position), new VectorModel(co.gameObject.transform.eulerAngles));
            localSaveModel.Coins.Add(model);
        }

        //https://www.sitepoint.com/saving-and-loading-player-game-data-in-unity/
        if (!Directory.Exists("Saves"))
        {
            Directory.CreateDirectory("Saves");
        }

        BinaryFormatter formatter = new BinaryFormatter();
        FileStream      saveFile  = File.Create("Saves/save.binary");

        formatter.Serialize(saveFile, localSaveModel);
        saveFile.Close();

        //http://gram.gs/gramlog/xml-serialization-and-deserialization-in-unity/
        XmlSerializer serializer = new XmlSerializer(typeof(SaveModel));
        StreamWriter  writer     = new StreamWriter("Saves/save.xml");

        serializer.Serialize(writer.BaseStream, localSaveModel);
        writer.Close();
    }