/// <summary>
        /// Converts from Constructables, if ready, to a cargo object, adding the cargo object to the factory's cargo.
        /// </summary>
        /// <param name="f"></param>
        /// <returns></returns>
        async Task _handleFactoryConstruction(Factory f)
        {
            CargoTransaction tr = null;

            switch (f.CompletedPendingInstantiation)
            {
            case Constructables.Null:
                tr = null;
                break;

            case Constructables.LaserTurret:
            {
                CargoLaserTurret t = new CargoLaserTurret(_galaxyIDManager.PopFreeID(), 666, new LaserWeaponStats());
                tr = new TransactionAddStatefulCargo(f, t, false);
                _cargoSynchronizer.RequestTransaction(tr);
                await tr.ResultTask;
                break;
            }
            }


            if (tr != null && tr.ResultTask.Result == CargoResult.Success)
            {
                f.CompletedPendingInstantiation = Constructables.Null;
            }
        }
Example #2
0
        /// <summary>
        /// Remember to call ship.SetPlayer and player.SetShip
        /// </summary>
        /// <param name="props"></param>
        /// <returns></returns>
        public IShip CreateShip(ShipCreationProperties props)
        {
            IShip tempShip = null;

            switch (props.PilotType)
            {
            case PilotTypes.Player:
                tempShip = new PlayerShip(ShipStatManager.TypeToStats[props.ShipType], _locatorService);
                break;

            case PilotTypes.NPC:
                tempShip = new NPCShip(ShipStatManager.TypeToStats[props.ShipType], _locatorService);
                break;

            case PilotTypes.Simulator:
                throw new NotImplementedException("ShipFactory.CreateShip not yet implemented for PilotTypes.Simulator");
            }


            tempShip.Id = _galaxyIdManager.PopFreeID();
            _galaxyRegistrationManager.RegisterObject(tempShip);

            foreach (var w in props.WeaponTypes)
            {
                tempShip.SetWeapon(WeaponManager.GetNewWeapon(w));
            }

            tempShip.PosX          = props.PosX;
            tempShip.PosY          = props.PosY;
            tempShip.CurrentEnergy = tempShip.ShipStats.Energy;

            _warpManager.MoveShipLocal(tempShip, props.AreaId);

            return(tempShip);
        }
Example #3
0
        /// <summary>
        /// Performs a bunch of checks and returns a created account if succesful
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="persistAccount">If false, account will not be stored in the manager or the db</param>
        /// <returns>Check flags if returned account is null</returns>
        public async Task <Tuple <Account, AccountCreationFailFlags> > CreateAccountAsync(string username, string password, bool persistAccount = true)
        {
            AccountCreationFailFlags failFlags = 0;

            // Checks
            _usernameCharCheck(username, ref failFlags);
            _passwordCheck(password, ref failFlags);
            var res = await _usernameExistsAsync(username, failFlags);

            failFlags = res.Item2;

            Account retAccount = null;

            if (failFlags == 0)
            {
#if DEBUG
                //ConsoleManager.WriteToFreeLine("Creating Account with username " + username);
#endif
                retAccount = new Account(username, password, _accountIDManager.PopFreeID(), false);
                if (persistAccount)
                {
                    await _databaseManager.SaveAsync(retAccount);

                    var writeResult = await _usernameExistsAsync(username, 0);

                    if (writeResult.Item1)
                    {
#if DEBUG
                        ConsoleManager.WriteLine("DB write failed when creating a new account.");
#endif
                        _accountIDManager.PushFreeID(retAccount.Id);
                        retAccount = null;
                        failFlags  = failFlags | AccountCreationFailFlags.DBWriteFailed;
                    }
                }
            }

            if (persistAccount && retAccount != null)
            {
                RegisterAccount(retAccount);
            }

            return(new Tuple <Account, AccountCreationFailFlags>(retAccount, failFlags));
        }
Example #4
0
        async Task AddCargoToPlayerShips(IEnumerable <IShip> ships, ILocalIDManager galaxyIDManager, GalaxyRegistrationManager registrationManager, CargoSynchronizer cargoSynchronizer)
        {
            //Making this into a grand test of transaction sequences, there's really no reason to put this all into one sequence
            CargoTransactionSequence cs = new CargoTransactionSequence();

            foreach (var s in ships)
            {
                for (int i = 0; i < _config.CARGO_NumTurrets; i++)//Sending ship state over a network might be painful while this is here...
                {
                    CargoLaserTurret            c = new CargoLaserTurret(galaxyIDManager.PopFreeID(), 666, new LaserWeaponStats());
                    TransactionAddStatefulCargo t = new TransactionAddStatefulCargo(s, c, true);
                    cs.Add(t);

                    registrationManager.RegisterObject(c);
                }

                TransactionAddStatelessCargo tr = new TransactionAddStatelessCargo(s, StatelessCargoTypes.AmbassadorMissile, _config.CARGO_NumMissiles, true);
                cs.Add(tr);

                tr = new TransactionAddStatelessCargo(s, StatelessCargoTypes.HellHoundMissile, _config.CARGO_NumMissiles, true);
                cs.Add(tr);
                tr = new TransactionAddStatelessCargo(s, StatelessCargoTypes.MissileType1, _config.CARGO_NumMissiles, true);
                cs.Add(tr);
                tr = new TransactionAddStatelessCargo(s, StatelessCargoTypes.MissileType2, _config.CARGO_NumMissiles, true);
                cs.Add(tr);
                tr = new TransactionAddStatelessCargo(s, StatelessCargoTypes.MissileType3, _config.CARGO_NumMissiles, true);
                cs.Add(tr);
                tr = new TransactionAddStatelessCargo(s, StatelessCargoTypes.MissileType4, _config.CARGO_NumMissiles, true);
                cs.Add(tr);

                tr = new TransactionAddStatelessCargo(s, StatelessCargoTypes.Biodome, _config.CARGO_NumBiodomes, true);
                cs.Add(tr);
            }
            cargoSynchronizer.RequestAtomicTransactionSequence(cs);
            await cs.ResultTask;

            if (cs.ResultTask.Result != CargoResult.Success)
            {
                ConsoleManager.WriteLine(cs.ResultTask.Result.ToString());
            }
            return;
        }