Example #1
0
    public void BeginCampaign(string balanceName)
    {
        gameBalance = Resources.Load <GameBalance>(balanceName);
        Debug.Assert(gameBalance != null);

        playerStats = gameObject.AddComponent <VesselStats>();
        playerStats.SetStats(new VesselStatValues());

        playerStatus = gameObject.AddComponent <VesselStatus>();
        //playerStatus.InitialiseFull(gameBalance, playerStats);

        encounter = null;

        state         = State.None;
        nextEncounter = 0;

        state = State.InitialStats;
        int remainingPoints = gameBalance.initialStatPoints;

        while (remainingPoints > 0)
        {
            int statCount = System.Enum.GetValues(typeof(VesselStats.Type)).Length;
            for (int i = 0; remainingPoints > 0 && i < statCount; ++i)
            {
                playerStats.SetRaw((VesselStats.Type)i, playerStats.GetRaw((VesselStats.Type)i) + 1);
                --remainingPoints;
            }
        }
        Game.Instance.pageManager.SetPage("InitialStats");
    }
Example #2
0
    // construct and configure
    public VesselEncounter(
        bool isPlayer,
        string name,
        Encounter owner,
        GameBalance balance,
        VesselVisuals visuals,
        VesselStats stats,
        VesselStatus status,
        VesselModifiers modifiers)
    {
        this.isPlayer  = isPlayer;
        this.name      = name;
        this.owner     = owner;
        this.balance   = balance;
        this.modifiers = modifiers;
        this.visuals   = visuals;

        Stats  = stats;
        Status = status;

        visuals.ResetVisibility();

        abilities = new Dictionary <string, VesselAbility>();
        InitialiseAbilities();
    }
Example #3
0
    public void BeginEncounter(Campaign owner, EncounterDescriptor descriptor)
    {
        this.owner      = owner;
        this.descriptor = descriptor;

        // setup opponent
        opponentStats = gameObject.AddComponent <VesselStats>();
        InitialiseOpponentStats();
        opponentStatus = gameObject.AddComponent <VesselStatus>();
        InitialiseOpponentStatus();

        // activate page
        pageEncounter = (PageEncounter)Game.Instance.pageManager.PushPage("Encounter");
        // disable input
        pageEncounter.IsInputEnabled = false;

        // initialise health bars
        pageEncounter.healthBarPlayer.SetFill(owner.playerStatus.GetHealthPercentage());
        pageEncounter.healthBarOpponent.SetFill(opponentStatus.GetHealthPercentage());

        // setup vessel encounters
        playerEncounter   = new VesselEncounter(true, "player", this, owner.gameBalance, pageEncounter.playerVisuals, owner.playerStats, owner.playerStatus, descriptor.playerModifiers);
        opponentEncounter = new VesselEncounter(false, "opponent", this, owner.gameBalance, pageEncounter.opponentVisuals, opponentStats, opponentStatus, descriptor.enemyModifiers);
        VesselEncounter.SetOpponents(playerEncounter, opponentEncounter);

        opponentAiBehaviour = Instantiate(descriptor.enemyAiBehaviour, transform);

        // start
        BeginPlayerTurn();
    }
        public object Convert(object value, System.Type targetType,
                              object parameter, CultureInfo culture)
        {
            VesselStatus status = (VesselStatus)value;

            switch (status)
            {
            case VesselStatus.ACTIVE:
                return((SolidColorBrush)
                       (new BrushConverter().ConvertFrom("#FF8CF699")));

            case VesselStatus.DESTROYED:
                return((SolidColorBrush)
                       (new BrushConverter().ConvertFrom("#FFFFADAD")));

            case VesselStatus.DESTROYED_WAITING_REPLACEMENT:
                return((SolidColorBrush)
                       (new BrushConverter().ConvertFrom("#FFFFADAD")));

            case VesselStatus.DRYDOCKED:
                return((SolidColorBrush)
                       (new BrushConverter().ConvertFrom("#FFFFD5AD")));

            case VesselStatus.DECOMMISSIONED:
                return(new SolidColorBrush(Colors.White));

            default:
                return(new SolidColorBrush(Colors.White));
            }
        }
Example #5
0
        public new void ToString()
        {
            var status = new VesselStatus(HInclinationStatus.S, -100000.1m, 2m, 1.99998m);

            var actual = status.ToString();

            Assert.AreEqual("S: -100000.1 / 2 - 1.99998 = 0.00002", actual);
        }
Example #6
0
 /// <summary>
 /// Callback function for the EditStatus window
 /// </summary>
 /// <param name="id"></param>
 /// <param name="status"></param>
 private void UpdateShipStatus(int id, VesselStatus status)
 {
     MessageRouter.Instance.Send(
         MessageRouter.Service.Main,
         new ANWI.Messaging.ChangeShipStatus(id, status),
         this
         );
 }
Example #7
0
        public void Create()
        {
            var actual = VesselStatus.Create("p", ".1", "-5", "-3", "-2.0");

            Assert.AreEqual(HInclinationStatus.P, actual.HStatus);
            Assert.AreEqual(0.1m, actual.HValue);
            Assert.AreEqual(-5m, actual.AftDraft);
            Assert.AreEqual(-3m, actual.ForeDraft);
            Assert.AreEqual(-2m, actual.VValue);
        }
Example #8
0
        public void Parse()
        {
            var actual = VesselStatus.Parse(" p : .1 / -5 - -3 = -2.0 ");

            Assert.AreEqual(HInclinationStatus.P, actual.HStatus);
            Assert.AreEqual(0.1m, actual.HValue);
            Assert.AreEqual(-5m, actual.AftDraft);
            Assert.AreEqual(-3m, actual.ForeDraft);
            Assert.AreEqual(-2m, actual.VValue);
        }
Example #9
0
        private List <Receipt> GetTestReceipts()
        {
            var list = new List <Receipt>
            {
                new Receipt
                {
                    No                      = "receipt 01",
                    VesselName              = "vessel 01",
                    Time                    = DateTime.Now,
                    ReceiptFor              = "Load",
                    PortOfShipment          = "port of shipment 01",
                    PortOfDestination       = "port of destination 01",
                    KindOfGoods             = null,
                    VesselStatus            = VesselStatus.Parse("p:1/5-3=2"),
                    TotalOfVolumeOfStandard = 0.1m,
                    TotalOfVolume           = 0.2m,
                    TotalOfVolumeOfWater    = 0.3m,
                    TotalOfMass             = 0.4m,
                    TotalOfVolumeOfPipes    = 0.5m,
                    OperaterName            = "OperaterName 01",
                    AgentName               = "AgentName 01",
                    ShipperName             = "ShipperName 01",
                    ConsignerName           = "ConsignerName 01",
                    ConsigneeName           = "ConsigneeName 01",
                    ReceiptType             = ReceiptType.DeliveryReceiptDestination
                },
                new Receipt
                {
                    No                      = "receipt 02",
                    VesselName              = "vessel 02",
                    Time                    = DateTime.Now,
                    ReceiptFor              = "Load",
                    PortOfShipment          = "port of shipment 02",
                    PortOfDestination       = "port of destination 02",
                    KindOfGoods             = null,
                    VesselStatus            = VesselStatus.Parse("S:-.1/-1--0.8=-.2"),
                    TotalOfVolumeOfStandard = 10.1m,
                    TotalOfVolume           = 10.2m,
                    TotalOfVolumeOfWater    = 10.3m,
                    TotalOfMass             = 10.4m,
                    TotalOfVolumeOfPipes    = 10.5m,
                    OperaterName            = "OperaterName 02",
                    AgentName               = "AgentName 02",
                    ShipperName             = "ShipperName 02",
                    ConsignerName           = "ConsignerName 02",
                    ConsigneeName           = "ConsigneeName 02",
                    ReceiptType             = ReceiptType.MassOfOil
                }
            };

            list[0].ReceiptTankDetails.AddRange(this.GetTestReceiptTankDetails());
            list[1].ReceiptTankDetails.AddRange(this.GetTestReceiptTankDetails());

            return(list);
        }
Example #10
0
        private static string GetHStatusDescription(VesselStatus vesselStatus)
        {
            if (vesselStatus == null)
            {
                return(null);
            }

            return(String.Format("{0} {1}{2}",
                                 vesselStatus.HStatus == HInclinationStatus.P ? Strings.ReportLabelListToPort : Strings.ReportLabelListToStarboard,
                                 vesselStatus.HValue,
                                 Strings.ReportLabelUnitDegree));
        }
Example #11
0
        private VesselViewModel SetVesselStatusInModel(VesselViewModel vessel)
        {
            VesselStatus status = _context.VesselStatus
                                  .Where(x => x.Code == vessel.RegistrationData.Status)
                                  .FirstOrDefault();

            if (status != null)
            {
                vessel.RegistrationData.StatusName   = status.Name;
                vessel.RegistrationData.StatusNameEn = status.NameEn;
            }

            return(vessel);
        }
Example #12
0
        private Receipt ReadReceipt(OleDbDataReader reader)
        {
            var readKindOfGoods = new Func <KindOfGoods>(() =>
            {
                var uid = reader["KindOfGoodsUId"].ToStringOrNull();
                if (uid == null)
                {
                    return(null);
                }

                var kind = new KindOfGoods {
                    UId = uid, Name = reader["KindOfGoodsName"].ToStringOrNull(), Customized = true
                };
                if (String.IsNullOrEmpty(kind.Name))
                {
                    var builtInKind = Const.BuiltInKindsOfGoods.FirstOrDefaultRecursively(k => k.UId.Equals(kind.UId));
                    if (builtInKind != null)
                    {
                        kind = builtInKind;
                    }
                }

                return(kind);
            });

            return(new Receipt
            {
                No = reader["No"].ToStringOrNull(),
                VesselName = reader["VesselName"].ToStringOrNull(),
                Time = reader["Time"].TryToNullableDateTime(),
                ReceiptFor = reader["ReceiptFor"].ToStringOrNull(),
                PortOfShipment = reader["PortOfShipment"].ToStringOrNull(),
                PortOfDestination = reader["PortOfDestination"].ToStringOrNull(),
                KindOfGoods = readKindOfGoods(),
                VesselStatus = VesselStatus.Parse(reader["VesselStatus"].ToStringOrNull()),
                TotalOfVolumeOfStandard = reader["TotalOfVolumeOfStandard"].TryToNullableDecimal(),
                TotalOfVolume = reader["TotalOfVolume"].TryToNullableDecimal(),
                TotalOfVolumeOfWater = reader["TotalOfVolumeOfWater"].TryToNullableDecimal(),
                TotalOfMass = reader["TotalOfMass"].TryToNullableDecimal(),
                TotalOfVolumeOfPipes = reader["TotalOfVolumeOfPipes"].TryToNullableDecimal(),
                OperaterName = reader["OperaterName"].ToStringOrNull(),
                AgentName = reader["AgentName"].ToStringOrNull(),
                ShipperName = reader["ShipperName"].ToStringOrNull(),
                ConsignerName = reader["ConsignerName"].ToStringOrNull(),
                ConsigneeName = reader["ConsigneeName"].ToStringOrNull(),
                TimeSaved = reader["TimeSaved"].TryToDateTime(),
                ReceiptType = reader["ReceiptType"].ToReceiptType()
            });
        }
Example #13
0
        public void VerifyThatShouldThrowWhileFormatInvalid()
        {
            Exception actual = null;

            try
            {
                VesselStatus.Parse("k : .1 / 4 - 2 = 2");
            }
            catch (Exception ex)
            {
                actual = ex;
            }

            Assert.AreEqual(typeof(FormatException), actual.GetType());
            Assert.AreEqual(@"invalid status string to parse, argument: s = k : .1 / 4 - 2 = 2", actual.Message);
        }
Example #14
0
        public void VerifyThatShouldThrowWhileEquationIsWrong()
        {
            Exception actual = null;

            try
            {
                VesselStatus.Parse("p : .1 / 4 - 2 = 3");
            }
            catch (Exception ex)
            {
                actual = ex;
            }

            Assert.AreEqual(typeof(FormatException), actual.GetType());
            Assert.AreEqual(@"illegal equation, argument: s = p : .1 / 4 - 2 = 3", actual.Message);
        }
Example #15
0
        public void GetReceiptHeader(Receipt receipt, bool validate = true)
        {
            if (validate)
            {
                var error = new[]
                {
                    this.txtReceiptNo.Text.ValidateNotEmpty(lblReceiptNo.Text, true),
                    this.txtVesselName.Text.ValidateNotEmpty(lblVesselName.Text, true),
                    this.txtTime.Text.ValidateDate(Strings.LabelTime),
                    (!this.rdoLoad.Checked && !this.rdoDischarge.Checked) ? String.Format(Strings.MsgValidationErrorCannotBeEmpty, Strings.LabelReceiptFor) : null,
                    this.txtPortOfShipment.Text.ValidateNotEmpty(lblPortOfShipment.Text, true),
                    this.txtPortOfDestination.Text.ValidateNotEmpty(lblPortOfDestination.Text, true),
                    this.cmbKindOfGoods.SelectedNode == null?String.Format(Strings.MsgValidationErrorCannotBeEmpty, lblKindOfGoods.Text) : null,
                        !VesselStatus.Validate(this.HStatus, this.txtHInclination.Text, this.txtAftDraft.Text, this.txtForeDraft.Text, this.txtVInclination.Text) ? String.Format(Strings.MsgValidationErrorInvalidVesselStatus, lblVesselStatus.Text) : null
                }
                .Where(e => e != null)
                .Aggregate(new StringBuilder(), (sb, e) => sb.AppendLine(e)).ToString();

                if (error.Length > 0)
                {
                    throw new ValidationException(error);
                }
            }

            var r = new Receipt();

            r.No                = this.txtReceiptNo.Text.Trim();
            r.VesselName        = this.txtVesselName.Text.Trim();
            r.Time              = this.txtTime.Text.Trim().TryToNullableDateTime();
            r.ReceiptFor        = this.rdoLoad.Checked ? "Load" : (this.rdoDischarge.Checked ? "Discharge" : String.Empty);
            r.PortOfShipment    = this.txtPortOfShipment.Text.Trim();
            r.PortOfDestination = this.txtPortOfDestination.Text.Trim();
            r.KindOfGoods       = this.cmbKindOfGoods.SelectedNode == null ? null : (KindOfGoods)this.cmbKindOfGoods.SelectedNode.Tag;
            try { r.VesselStatus = VesselStatus.Create(this.HStatus, this.txtHInclination.Text, this.txtAftDraft.Text, this.txtForeDraft.Text, this.txtVInclination.Text); } catch { }
            r.TotalOfVolumeOfPipes = this.TotalOfVolumeOfPipes;

            receipt.No                   = r.No;
            receipt.VesselName           = r.VesselName;
            receipt.Time                 = r.Time;
            receipt.ReceiptFor           = r.ReceiptFor;
            receipt.PortOfShipment       = r.PortOfShipment;
            receipt.PortOfDestination    = r.PortOfDestination;
            receipt.KindOfGoods          = r.KindOfGoods;
            receipt.VesselStatus         = r.VesselStatus;
            receipt.TotalOfVolumeOfPipes = r.TotalOfVolumeOfPipes;
        }
        /// <summary>
        /// For converting the vessel status into a string for the UI
        /// </summary>
        /// <param name="status"></param>
        /// <returns></returns>
        public static string ToFriendlyString(this VesselStatus status)
        {
            switch (status)
            {
            case VesselStatus.ACTIVE:
                return("Active");

            case VesselStatus.DESTROYED:
                return("Destroyed");

            case VesselStatus.DESTROYED_WAITING_REPLACEMENT:
                return("Destroyed (Awaiting Replacement)");

            case VesselStatus.DRYDOCKED:
                return("Drydocked");

            case VesselStatus.DECOMMISSIONED:
                return("Decommissioned/Sold");

            default:
                return("Unknown");
            }
        }
 public ChangeShipStatus(int ship, VesselStatus stat)
 {
     shipId = ship;
     status = stat;
 }
 public ChangeShipStatus()
 {
     shipId = 0;
     status = VesselStatus.ACTIVE;
 }
        internal void WatchForLanding()
        {
            if (!Utils.vesselInFlight)
                return;
            Log.Info("LandingMonitor: WatchForLanding, time: " + Planetarium.GetUniversalTime().ToString("n2") + ",  vesselsLoaded.Count: " + FlightGlobals.fetch.vesselsLoaded.Count().ToString());
            for (int x = FlightGlobals.fetch.vesselsLoaded.Count() - 1; x >= 0; x--)
            {
                var v = FlightGlobals.fetch.vesselsLoaded[x];
                VesselStatus vesselStatus = null;
                try
                {
                    vesselStatus = vesselLandedDict[v.id];
                }
                catch (KeyNotFoundException)
                {
                    vesselStatus = new VesselStatus(v);
                    vesselLandedDict.Add(v.id, vesselStatus);
                }
                if (vesselStatus == null)
                {
                    Log.Error("WatchForLanding, vesselStatus is null");
                }
                if (v.Landed != vesselStatus.Landed)
                    vesselStatus.SetLandedTime(v.Landed);
                if (v.Splashed != vesselStatus.Splashed)
                    vesselStatus.SetSplashedTime(v.Splashed);

                /* Flying definition
                   1. Altitude > 50m
                   2.  Not touching the ground for 5 seconds                   
                 */
                if (v.heightFromTerrain >= HighLogic.CurrentGame.Parameters.CustomParams<KL_13>().minFlyingAltitude)
                {
                    Log.Info("LandingMonitor: v.heightFromTerrain: " + v.heightFromTerrain.ToString());
                    if (!vesselStatus.Flying)
                        vesselStatus.SetFlyingTime(true);

                    if (vesselStatus.Flying &&
                       Planetarium.GetUniversalTime() - vesselStatus.universalTime >= HighLogic.CurrentGame.Parameters.CustomParams<KL_13>().minFlyingTime)
                    {
                        vesselStatus.SetFlyingEvent();
                    }
                }

                /* Landing definition
                    1.  Touching the ground
                    2.  speed less than 0.05
                    3.  Stable for 5 seconds
                */
                if (!vesselStatus.landedEvent && v.Landed &&
                    Planetarium.GetUniversalTime() - vesselStatus.universalTime >= HighLogic.CurrentGame.Parameters.CustomParams<KL_13>().landedStabilityTime &&
                    v.speed < 0.05f)
                {
                    Log.Info("LandingMonitor: Triggering landed event");
                    vesselStatus.landedEvent = true;
                    vesselStatus.Flying = false;
                    Utils.instance.onVesselLanded(v);
                }

            }
        }