Beispiel #1
0
        public HttpResponseMessage MyViewedActivities(ActivityStage stage, string filterSource, string sortByKey, bool isAscending, int pageIndex, int pageSize)
        {
            if (ValidationService.AuthorizeToken(GetToken(), "get:/api/volunteer/viewedactivities?stage=&filterSource=&sortByKey=&isAscending=&pageIndex=&pageSize=") == false)
            {
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text")
                });
            }
            User currentUser = ValidationService.FindUserWithToken(GetToken());

            if (!currentUser.UserRole.Contains(Role.Volunteer))
            {
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text")
                });
            }
            List <Activity>           activities = myService.FindAllActivitiesWhichVolunteerViewed(currentUser, filterSource, sortByKey, isAscending, pageIndex, pageSize).ToList <Activity>();
            List <ActivityToListShow> result     = transformActivityToListShow(activities, currentUser);
            StringWriter   tw             = new StringWriter();
            JsonSerializer jsonSerializer = new JsonSerializer();

            jsonSerializer.Serialize(tw, result, result.GetType());
            return(new HttpResponseMessage {
                Content = new StringContent(tw.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
            });
        }
Beispiel #2
0
        public HttpResponseMessage MyFavoriteActivities(ActivityStage stage, string filterSource, string sortByKey, bool isAscending, int pageIndex, int pageSize)
        {
            if (ValidationService.AuthorizeToken(GetToken(), "get:/api/volunteer/favorite?stage=&filterSource=&sortByKey=&isAscending=&pageIndex=&pageSize=") == false)
            {
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text")
                });
            }
            User currentUser = ValidationService.FindUserWithToken(GetToken());

            if (!currentUser.UserRole.Contains(Role.Volunteer))
            {
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text")
                });
            }
            IEnumerable <Activity> source;

            switch (stage)
            {
            //找到所有非draft状态的activity
            case ActivityStage.all:
                source = myService.FindAllActivitiesWhichVolunteerFavorite(currentUser, filterSource, sortByKey, isAscending, pageIndex, pageSize);
                break;

            //即将开始的activity(处于active、maxVolunteer、ready、signIn状态下的)
            case ActivityStage.aboutToStart:
                source = myService.FindAboutToStartActivitiesWhichVolunteerFavorite(currentUser, filterSource, sortByKey, isAscending, pageIndex, pageSize);
                break;

            //正在进行的活动(处于RunningCheckIn、RunningRun状态下的)
            case ActivityStage.running:
                source = myService.FindRunningActivitiesWhichVolunteerFavorite(currentUser, filterSource, sortByKey, isAscending, pageIndex, pageSize);
                break;

            //已经完成的活动(处于Finished状态下的)
            case ActivityStage.finish:
                source = myService.FindFinishedActivitiesWhichVolunteerFavorite(currentUser, filterSource, sortByKey, isAscending, pageIndex, pageSize);
                break;

            default:
                return(new HttpResponseMessage {
                    StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("stage参数错误", System.Text.Encoding.GetEncoding("UTF-8"), "application/text")
                });
            }
            List <ActivityToListShow> result = transformActivityToListShow(source, currentUser);
            StringWriter   tw             = new StringWriter();
            JsonSerializer jsonSerializer = new JsonSerializer();

            jsonSerializer.Serialize(tw, result, result.GetType());
            return(new HttpResponseMessage {
                Content = new StringContent(tw.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
            });
        }
 public void ActivatePier()
 {
     if (GameMaster.loading)
     {
         return;
     }
     if (currentStage == ActivityStage.InnerRingBuilding)
     {
         currentStage = ActivityStage.PierPreparing;
         LoadSmallGear();
         liftObject       = true;
         poweringProgress = 0f;
         PrepareMainLine();
     }
 }
 public void StartActivating()
 {
     if (GameMaster.loading)
     {
         return;
     }
     if (currentStage == ActivityStage.AwaitingPowering)
     {
         currentStage     = ActivityStage.PoweringUp;
         poweringProgress = 0f;
         GameMaster.audiomaster.MakeSoundEffect(SoundEffect.FD_anchorLaunch);
         PrepareMainLine();
         LoadHexBasement();
         // добавить влияние на global map и вывод сообщения о том, что оcтров заякорен
     }
 }
 public void StartTransportingColonists()
 {
     if (GameMaster.loading)
     {
         return;
     }
     if (currentStage == ActivityStage.PierPreparing)
     {
         currentStage       = ActivityStage.OuterRingBuilding;
         transportColonists = true;
         if (colonistsShip == null)
         {
             LoadColonistsShip();
         }
         SetShipStartPosition();
     }
 }
 /// <summary>
 /// 绘制组,获取当前活动时的小组信息
 /// </summary>
 /// <param name="map"></param>
 /// <param name="_activityGuid"></param>
 /// <param name="stageType"></param>
 public static void DrawOrgsToMap(MapGIS map, string _activityGuid, ActivityStage stageType, ContextMenu menu = null)
 {
     map.RemoveElementByFlag(MapGroupTypes.MonitorGroup_.ToString());
     ScheduleDetail[] scheduleDetails = Utility.getOrgGroupsBySchedule(_activityGuid, stageType);
     if (scheduleDetails != null && scheduleDetails.Length > 0)
     {
         foreach (ScheduleDetail detail in scheduleDetails)
         {
             PP_OrgInfo orginfo = detail.ScheduleOrgs[0].OrgInfo;
             orginfo.OnLine = null;
             OrgToMapStyle group = new OrgToMapStyle(orginfo);
             if (menu != null)
             {
                 group.ContextMenu = menu;
             }
             map.AddElement(group, map.GetMapPointEx(detail.ScheduleOrgs[0].LONGITUDE, detail.ScheduleOrgs[0].LATITUDE));
         }
     }
 }
    override public void Load(System.IO.Stream fs, Plane sblock)
    {
        base.Load(fs, sblock);
        var x = fs.ReadByte();

        currentStage = (ActivityStage)x;
        byte[] data;
        bool   loadBasement = true, loadBigGear = true, loadSmallGear = true;

        switch (currentStage)
        {
        case ActivityStage.BasementBuilt:
            data = new byte[4];
            fs.Read(data, 0, data.Length);
            poweringProgress = BitConverter.ToSingle(data, 0);
            break;

        case ActivityStage.AwaitingPowering:
            loadBasement = fs.ReadByte() == 1;
            break;

        case ActivityStage.PoweringUp:
            data = new byte[5];
            fs.Read(data, 0, data.Length);
            poweringProgress = BitConverter.ToSingle(data, 0);
            loadBasement     = data[4] == 1;
            break;

        case ActivityStage.InnerRingBuilding:
            data = new byte[6];
            fs.Read(data, 0, data.Length);
            liftObject       = data[0] == 1;
            poweringProgress = BitConverter.ToSingle(data, 1);
            loadBigGear      = data[5] == 1;
            break;

        case ActivityStage.PierPreparing:
            data = new byte[6];
            fs.Read(data, 0, data.Length);
            liftObject       = data[0] == 1;
            poweringProgress = BitConverter.ToSingle(data, 1);
            loadSmallGear    = data[5] == 1;
            break;

        case ActivityStage.OuterRingBuilding:
        {
            transportColonists = (fs.ReadByte() == 1);
            shipStatus         = (ShipStatus)fs.ReadByte();
            void LoadShipPosition()
            {
                if (colonistsShip == null)
                {
                    LoadColonistsShip();
                }
                colonistsShip.position = new Vector3(
                    BitConverter.ToSingle(data, 0),
                    BitConverter.ToSingle(data, 4),
                    BitConverter.ToSingle(data, 8)
                    );
                colonistsShip.forward = new Vector3(
                    BitConverter.ToSingle(data, 12),
                    BitConverter.ToSingle(data, 16),
                    BitConverter.ToSingle(data, 20)
                    );
            }

            switch (shipStatus)
            {
            case ShipStatus.ComingToPier:
            case ShipStatus.Leaving:
                data = new byte[24];
                fs.Read(data, 0, data.Length);
                LoadShipPosition();
                break;

            case ShipStatus.Docking:
                data = new byte[28];
                fs.Read(data, 0, data.Length);
                LoadShipPosition();
                shipTimer = BitConverter.ToSingle(data, 24);
                break;

            case ShipStatus.WaitingForNextShip:
                data = new byte[4];
                fs.Read(data, 0, data.Length);
                shipTimer = BitConverter.ToSingle(data, 0);
                break;
            }
            data = new byte[4];
            fs.Read(data, 0, data.Length);
            colonistsArrived = BitConverter.ToInt32(data, 0);
            break;
        }
        }

        if (currentStage > ActivityStage.BasementBuilt)
        {
            endCrystal.position = outerRingZeroPoint;
            if (currentStage > ActivityStage.AwaitingPowering)
            {
                if (loadBasement)
                {
                    LoadHexBasement();
                }
                if (currentStage > ActivityStage.PoweringUp)
                {
                    if (loadBigGear)
                    {
                        LoadBigGear();
                    }
                    var p = innerRingZeroPoint;
                    hexBasement.position = p;
                    if (currentStage > ActivityStage.InnerRingBuilding)
                    {
                        bigGear.position = p;
                        if (loadSmallGear)
                        {
                            LoadSmallGear();
                        }
                        if (currentStage > ActivityStage.InnerRingBuilding)
                        {
                            smallGear.position = pierPosition;
                        }
                    }
                    else
                    {
                        if (!liftObject)
                        {
                            bigGear.position = p;
                        }
                    }
                }
            }
        }
        PrepareMainLine();
        var s_innerSectorsBuilt = (byte)fs.ReadByte();

        if (s_innerSectorsBuilt != 0)
        {
            for (byte i = 0; i < s_innerSectorsBuilt; i++)
            {
                AddInnerSector(i);
            }
        }

        if (!isActive)
        {
            SetActivationStatus(true, true);
        }
    }
    public void Update()
    {
        if (GameMaster.loading)
        {
            return;
        }
        var t = Time.deltaTime * GameMaster.gameSpeed;

        switch (currentStage)
        {
        case ActivityStage.BasementBuilt:
        {
            poweringProgress    = Mathf.MoveTowards(poweringProgress, 1f, PADS_LIFT_SPEED * t * 0.1f);
            endCrystal.position = Vector3.Lerp(transform.position, outerRingZeroPoint + Vector3.down * 3f, poweringProgress);
            mainLine.SetPosition(1, endCrystal.transform.position);
            if (poweringProgress >= 1f)
            {
                scenario.Next();
                currentStage = ActivityStage.AwaitingPowering;
                endCrystal.GetComponent <Rotator>().SetRotationVector(Vector3.up * 5f);
            }
            break;
        }

        case ActivityStage.PoweringUp:
            if (poweringProgress < 1f)
            {
                float energyBoost = colony.energySurplus / MAX_EXCESS_POWER;
                if (energyBoost >= 1f)
                {
                    energyBoost = 1f;
                }
                poweringProgress    += (POWERING_SPEED + energyBoost) * t;
                hexBasement.position = Vector3.Lerp(transform.position, innerRingZeroPoint, poweringProgress);
                if (poweringProgress >= 1f)
                {
                    // special sound?
                    currentStage = ActivityStage.InnerRingBuilding;
                    LoadBigGear();
                    bigGear.position = transform.position;
                    scenario.AnchorPoweredUp();
                    poweringProgress = 0f;
                    liftObject       = true;
                }
            }
            break;

        case ActivityStage.InnerRingBuilding:
        {
            if (liftObject && poweringProgress < 1f)
            {
                float energyBoost = colony.energySurplus / MAX_EXCESS_POWER;
                if (energyBoost >= 1f)
                {
                    energyBoost = 1f;
                }
                poweringProgress += (POWERING_SPEED + energyBoost) * t * 0.5f;
                bigGear.position  = Vector3.Lerp(transform.position, innerRingZeroPoint, poweringProgress);
                if (poweringProgress >= 1f)
                {
                    poweringProgress = 0f;
                    liftObject       = false;
                    scenario.AnchorBigGearReady();
                }
            }
            break;
        }

        case ActivityStage.PierPreparing:
        {
            if (liftObject && poweringProgress < 1f)
            {
                float energyBoost = colony.energySurplus / MAX_EXCESS_POWER;
                if (energyBoost >= 1f)
                {
                    energyBoost = 1f;
                }
                poweringProgress  += (POWERING_SPEED + energyBoost) * t;
                smallGear.position = Vector3.Lerp(transform.position, pierPosition, poweringProgress);
                if (poweringProgress >= 1f)
                {
                    liftObject = false;
                    scenario.OKButton();
                }
            }
            break;
        }

        case ActivityStage.OuterRingBuilding:
        {
            float step = 0f;
            if (transportColonists)
            {
                if (shipStatus != ShipStatus.Disabled)
                {
                    switch (shipStatus)
                    {
                    case ShipStatus.ComingToPier:
                        float brakingDistances = shipSpeed * shipSpeed / SHIP_ACCELERATION / 2f;
                        if (brakingDistances >= distanceToPier)
                        {
                            shipSpeed = Mathf.MoveTowards(shipSpeed, 0f, SHIP_ACCELERATION * 10f * t);
                        }
                        step            = shipSpeed * t;
                        distanceToPier -= step;
                        if (distanceToPier > 1f)
                        {
                            colonistsShip.Translate(Vector3.forward * step, Space.Self);
                        }
                        else
                        {
                            shipSpeed  = 0f;
                            shipStatus = ShipStatus.Docking;
                            shipTimer  = SHIP_DOCKING_TIME;
                        }
                        break;

                    case ShipStatus.Docking:
                        shipTimer -= t;
                        if (shipTimer <= 0f)
                        {
                            ShipDocked();
                            shipStatus     = ShipStatus.Leaving;
                            distanceToPier = 0f;
                        }
                        break;

                    case ShipStatus.Leaving:
                        if (shipSpeed < SHIP_MAX_SPEED)
                        {
                            shipSpeed      += SHIP_ACCELERATION * t;
                            step            = shipSpeed * t;
                            distanceToPier += step;
                            if (distanceToPier < SHIP_SPAWN_DISTANCE)
                            {
                                colonistsShip.Translate(Vector3.forward * step, Space.Self);
                            }
                            else
                            {
                                colonistsShip.gameObject.SetActive(false);
                                shipSpeed  = 0f;
                                shipStatus = ShipStatus.WaitingForNextShip;
                                shipTimer  = SHIP_AWAITING_TIME;
                            }
                        }
                        break;

                    case ShipStatus.WaitingForNextShip:
                        shipTimer -= t;
                        if (shipTimer <= 0f)
                        {
                            SetShipStartPosition();
                        }
                        break;
                    }
                }
            }
            if (colony.citizenCount < colonistsArrived)
            {
                colonistsArrived = colony.citizenCount;
            }
            break;
        }
        }
    }
    override public void SetBasement(Plane b, PixelPosByte pos)
    {
        if (b == null)
        {
            return;
        }
        SetBuildingData(b, pos, true);
        currentStage        = ActivityStage.BasementBuilt;
        poweringProgress    = 0f;
        endCrystal          = Instantiate(Resources.Load <GameObject>(FoundationRouteScenario.resourcesPath + "fd_endCrystal")).transform;
        endCrystal.position = transform.position;
        endCrystal.GetComponent <Rotator>().SetRotationVector(Vector3.up * 25f);
        pierPosition = new Vector3(transform.position.x, PIER_HEIGHT, transform.position.z);
        PrepareMainLine();
        var   chunk = basement.myChunk;
        var   cpos  = basement.pos;
        Plane p;

        void CheckAndBlock(in ChunkPos position)
        {
            Block bx = chunk.GetBlock(position);

            if (bx != null && bx.TryGetPlane(Block.UP_FACE_INDEX, out p))
            {
                p.BlockByStructure(this, true);
            }
        }

        ChunkPos cpos2 = new ChunkPos(cpos.x - 1, cpos.y, cpos.z + 1); if (cpos2.isOkay)

        {
            CheckAndBlock(cpos2);
        }

        cpos2 = new ChunkPos(cpos.x, cpos.y, cpos.z + 1); if (cpos2.isOkay)
        {
            CheckAndBlock(cpos2);
        }
        cpos2 = new ChunkPos(cpos.x + 1, cpos.y, cpos.z + 1); if (cpos2.isOkay)
        {
            CheckAndBlock(cpos2);
        }
        cpos2 = new ChunkPos(cpos.x - 1, cpos.y, cpos.z); if (cpos2.isOkay)
        {
            CheckAndBlock(cpos2);
        }
        cpos2 = new ChunkPos(cpos.x + 1, cpos.y, cpos.z); if (cpos2.isOkay)
        {
            CheckAndBlock(cpos2);
        }
        cpos2 = new ChunkPos(cpos.x - 1, cpos.y, cpos.z - 1); if (cpos2.isOkay)
        {
            CheckAndBlock(cpos2);
        }
        cpos2 = new ChunkPos(cpos.x, cpos.y, cpos.z - 1); if (cpos2.isOkay)
        {
            CheckAndBlock(cpos2);
        }
        cpos2 = new ChunkPos(cpos.x + 1, cpos.y, cpos.z - 1); if (cpos2.isOkay)
        {
            CheckAndBlock(cpos2);
        }
        chunk.TryBlockVerticalCorridor(cpos.OneBlockDown(), false, this, ref blockersList, false);
        //
        if (!GameMaster.loading)
        {
            ProtectBasementBlocks();
        }
        else
        {
            GameMaster.realMaster.afterloadRecalculationEvent += this.ProtectBasementBlocks;
        }
    }