#pragma warning restore 1998

        /// <summary>
        /// Checks whether the given field should be active or not.
        /// </summary>
        /// <param name="state">The current state i.e. details for the watch filled so far.</param>
        /// <param name="propertyName">The name of the field to check.</param>
        /// <returns>True, if the given field should be active (has values). False otherwise.</returns>
        private static bool SetFieldActive(Spaceship spaceshipState, string propertyName)
        {
            bool          setActive     = true;
            SpaceshipData spaceshipData = SpaceshipData.Instance;

            if (spaceshipData.LastSearchResults != null)
            {
                if (spaceshipData.LastSearchResults.Count < 2)
                {
                    // There's only one or no options left - it makes no sense to ask anymore questions
                    setActive = false;
                }

                if (OptionsLeftForProperty(spaceshipData.LastSearchResults, propertyName).Count < 2)
                {
                    // There's only one or no options left for the given property - again this question is pointless
                    setActive = false;
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine($"Failed to check if not to set the field active for property {propertyName} due to missing search results");
            }

            System.Diagnostics.Debug.WriteLine($"Set field active for property {propertyName}: {setActive}");
            return(setActive);
        }
#pragma warning disable 1998
        /// <summary>
        /// Sets the values for the given field.
        /// </summary>
        /// <param name="spaceshipState">The current state i.e. details for the watch filled so far.</param>
        /// <param name="propertyName">The name of the property (field).</param>
        /// <param name="field">The field to populate.</param>
        /// <returns>True, if values found and field populated. False otherwise.</returns>
        private static async Task <bool> SetOptionsForFieldsAsync(
            Spaceship spaceshipState, string propertyName, Field <Spaceship> field)
        {
            bool          valuesSet     = false;
            SpaceshipData spaceshipData = SpaceshipData.Instance;

            if (spaceshipData.LastSearchResults != null)
            {
                // Clear the values to avoid duplicates since this method can be called many times
                field.RemoveValues();

                IList <object> values = OptionsLeftForProperty(spaceshipData.LastSearchResults, propertyName);

                foreach (object value in values)
                {
                    System.Diagnostics.Debug.WriteLine($"Adding value {value} for property {propertyName} to field {field.Name}");
                    string valueInTitleCase = CamelCaseToTitleCase(value.ToString());

                    field
                    .AddDescription(value, valueInTitleCase)
                    .AddTerms(value, valueInTitleCase);

                    valuesSet = true;
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine($"Failed to set values for property {propertyName} due to missing search results");
            }

            return(valuesSet);
        }
示例#3
0
 public SpaceshipMotor(IShipInput input, SpaceshipData data, Rigidbody2D ship, Direction direction) // Инициализируемся
 {
     _input     = input;
     _data      = data;
     _ship      = ship;
     _direction = direction;
     _ship.drag = _data.Drag;
 }
示例#4
0
    public void ResetShip(SpaceshipData data)
    {
        spaceshipData = data;
        GetComponent <SpriteRenderer>().sprite = spaceshipData.sprite;
        transform.position = new Vector2(0, -10);
        problems           = new List <ShipDefect>();

        onShipReset.Invoke();
    }
示例#5
0
    public SpaceshipData Clone()
    {
        SpaceshipData res = ScriptableObject.CreateInstance <SpaceshipData>();

        res.life    = life;
        res.lifeMax = lifeMax;
        res.speed   = speed;
        res.freq    = freq;
        return(res);
    }
    private void Awake()
    {
        rb = GetComponent <Rigidbody>();

        if (data == null)
        {
            data = new SpaceshipData();
        }

        data.OutputData();
    }
示例#7
0
 public override void ShootBehaviour(Transform transform, SpaceshipData attributes, List <Weapon.Turret> weapon, ref float t)
 {
     if (t > 1F / attributes.freq)
     {
         for (int i = 0; i < weapon.Count; ++i)
         {
             weapon[i].Fire();
         }
         t = 0f;
     }
 }
#pragma warning disable 1998
        /// <summary>
        /// Validates the response and does a new search with the updated parameters.
        /// </summary>
        /// <param name="response">The response from the user.</param>
        /// <param name="spaceshipState">The current state of the form (what details we have gathered to our spaceship).</param>
        /// <param name="propertyName">The name of the property queried.</param>
        /// <returns>The validation result.</returns>
        private static async Task <ValidateResult> ValidateResponseAsync(
            object response, Spaceship spaceshipState, string propertyName)
        {
            Spaceship         spaceshipSearchFilter = new Spaceship(spaceshipState);
            object            value         = Spaceship.VerifyPropertyValue(response, propertyName);
            SpaceshipData     spaceshipData = SpaceshipData.Instance;
            IList <Spaceship> matches       = null;

            if (spaceshipSearchFilter.SetPropertyValue(value, propertyName))
            {
                matches = spaceshipData.SearchForPartialMatches(spaceshipSearchFilter);
            }

            bool isValid = (matches != null && matches.Count > 0);

            ValidateResult validateResult = new ValidateResult
            {
                IsValid = (isValid && value != null),
                Value   = value
            };

            string feedbackMessage = string.Empty;

            if (!isValid)
            {
                // Since this was an invalid option, undo the change
                spaceshipState.ClearPropertyValue(propertyName);

                string valueAsString = ValueToString(value);
                System.Diagnostics.Debug.WriteLine($"Value {valueAsString} for property {propertyName} is invalid");
                feedbackMessage = $"\"{valueAsString}\" is not a valid option";
            }
            else
            {
                // Store the search
                spaceshipData.LastSearchResults = matches;
            }

            if (matches != null && matches.Count > 5)
            {
                feedbackMessage = $"Still {matches.Count} options matching your criteria. Let's get some more details!";
            }

            if (!string.IsNullOrEmpty(feedbackMessage))
            {
                System.Diagnostics.Debug.WriteLine(feedbackMessage);
                validateResult.Feedback = feedbackMessage;
            }

            return(validateResult);
        }
#pragma warning restore 1998

        /// <summary>
        /// Called once the form is complete. The result will have the properties selected by the user.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        private async Task OnSpaceshipSelectionFormCompleteAsync(IDialogContext context, IAwaitable <Spaceship> result)
        {
            Spaceship spaceship = null;

            try
            {
                spaceship = await result;
            }
            catch (FormCanceledException e)
            {
                System.Diagnostics.Debug.WriteLine($"Form canceled: {e.Message}");
            }

            if (spaceship != null)
            {
                System.Diagnostics.Debug.WriteLine($"We've got the criteria for the ship:\n{spaceship.PropertiesAsFormattedString()}");
                SpaceshipData spaceshipData = SpaceshipData.Instance;
                _spaceshipMatches = spaceshipData.SearchForPartialMatches(spaceship);

                if (_spaceshipMatches.Count == 1)
                {
                    // Single match for the given property -> Choise is made!
                    IMessageActivity messageActivity = context.MakeMessage();
                    ThumbnailCard    thumbnailCard   = CreateSpaceshipThumbnailCard(_spaceshipMatches[0]);
                    messageActivity.Attachments = new List <Attachment>()
                    {
                        thumbnailCard.ToAttachment()
                    };
                    messageActivity.Text = $"You've chosen \"{_spaceshipMatches[0].Name}\", well done!";
                    await context.PostAsync(messageActivity);

                    context.Done(_spaceshipMatches[0]);
                }
                else if (_spaceshipMatches.Count > 1)
                {
                    // More than one match -> Show the available options
                    await ShowSelectSpaceshipPromptAsync(context);
                }
                else
                {
                    // Nothing found matching the given criteria
                    await context.PostAsync("No spaceships found with the given criteria");

                    context.Fail(new ArgumentException("No spaceships found with the given criteria"));
                }
            }
            else
            {
                context.Fail(new NullReferenceException("No spaceship :("));
            }
        }
        /// <summary>
        /// Called when the user selects a spaceship from the shown options.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        private async Task OnSpaceshipSelectedAsync(IDialogContext context, IAwaitable <object> result)
        {
            object awaitedResult = await result;
            string spaceshipName = null;

            if (awaitedResult != null)
            {
                if (awaitedResult is Activity)
                {
                    spaceshipName = (awaitedResult as Activity).Text;
                }
                else
                {
                    spaceshipName = awaitedResult.ToString();
                }
            }

            if (!string.IsNullOrEmpty(spaceshipName))
            {
                SpaceshipData spaceshipData     = SpaceshipData.Instance;
                Spaceship     selectedSpaceship = null;

                try
                {
                    selectedSpaceship = spaceshipData.Spaceships.First(spaceship => spaceship.Name.Equals(spaceshipName));
                }
                catch (InvalidOperationException)
                {
                    await context.PostAsync($"\"{spaceshipName}\" is not a valid option, please try again");
                }

                if (selectedSpaceship != null)
                {
                    IMessageActivity messageActivity = context.MakeMessage();
                    ThumbnailCard    thumbnailCard   = CreateSpaceshipThumbnailCard(selectedSpaceship);
                    messageActivity.Attachments = new List <Attachment>()
                    {
                        thumbnailCard.ToAttachment()
                    };
                    messageActivity.Text = $"\"{spaceshipName}\" it is, great choice!";
                    await context.PostAsync(messageActivity);

                    context.Done(selectedSpaceship);
                }
                else
                {
                    await ShowSelectSpaceshipPromptAsync(context);
                }
            }
        }
示例#11
0
        public override void ShootBehaviour(Transform transform, SpaceshipData attributes, List <Weapon.Turret> weapon, ref float t)
        {
            Vector3 dir = target.position - transform.position;

            dir.y = 0f;
            transform.rotation = Quaternion.LookRotation(dir, Vector3.up);
            if (t > 1F / attributes.freq)
            {
                for (int i = 0; i < weapon.Count; ++i)
                {
                    weapon[i].Fire();
                }
                t = 0f;
            }
        }
示例#12
0
        public Spaceship(SpaceshipData spaceshipData, bool loadPhysics = false, Mothership.Team team = Mothership.Team.green) : base("")
        {
            this.team = team;

            this.spaceshipData = spaceshipData;

            rarity = (Rarity)spaceshipData.rarity;

            load(spaceshipData.level,
                 spaceshipData.baseDamage,
                 spaceshipData.baseLife,
                 spaceshipData.baseSpeed,
                 spaceshipData.baseRange,
                 spaceshipData.skin,
                 new Color(spaceshipData.colorRed, spaceshipData.colorGreen, spaceshipData.colorBlue),
                 loadPhysics);
        }
示例#13
0
    private float speedResultNormalize;                                         //Нормализованная скорость, к которой стремимся
    #endregion

    #region Public methods
    public SpaceshipMetadata(SpaceshipData _data, SpaceshipsConfig _config, bool _isPlayer)
    {
        data     = _data;
        config   = _config;
        isPlayer = _isPlayer;

        mk      = data.mk;
        mkIndex = data.GetMkIndex();

        ApplySubsystems();
        ApplyWeapons();
        ApplySlots();
        ApplyItems();

        ApplyMaxParameters();
        ApplyParameters();

        ApplyDefault();
    }
示例#14
0
    public void InitializeSpaceship()
    {
        //Input
        ApplyInpytComponent();

        //coroutine = null;
        speedCoroutine = null;
        point          = null;
        targets.Clear();

        data = Global.Instance.PROFILE.spaceships.Find(x => x.model == model);
        if (data == null)
        {
            //Debug.LogWarning("<color=#FF0000>[SpaceshipController] \"data\" is null!</color>");
            //model = "ERROR";
            //return;

            data = new SpaceshipData(model);

            //TODO: TEST
            data.ApplyDefault();

            Global.Instance.PROFILE.spaceships.Add(data);
        }

        config = data.GetConfig();

        meta = new SpaceshipMetadata(data, config, isPlayer);

        SizeType = (EnumSizeType)config.sizeType;

        ApplyWeapons();

        material = data.material;
        //LoadedMainMesh();
        LoadedMainMaterial();

        Title = string.Format("{0} MK-{1}", data.model.ToUpper(), data.mk);

        CreateMarker();
    }
示例#15
0
    public void DockShip(SpaceshipData shipData)
    {
        Debug.Log($"Preparing to dock {shipData.name}");
        spaceship.ResetShip(shipData);

        foreach (SlotCode slot in shipData.slots)
        {
            if (Random.Range(1, 11) < 3)
            {
                spaceship.CreateDefects(slot, itemsManager.GetRandomItem());
            }
        }

        foreach (HangarSlotComponent slotComponent in slots)
        {
            if (shipData.slots.Contains(slotComponent.hangarCode))
            {
                slotComponent.status = SlotStatus.REGULAR;
            }
            else
            {
                slotComponent.status = SlotStatus.NOT_PRESENT;
            }

            if (spaceship.problems.Exists(p => p.slot == slotComponent.hangarCode))
            {
                slotComponent.status         = SlotStatus.DEFECTIVE;
                slotComponent.materialNeeded = spaceship.problems.Find(p => p.slot == slotComponent.hangarCode).item;
                //slotComponent.itemSprite.sprite = slotComponent.materialNeeded.sprite;
            }
            else
            {
                slotComponent.materialNeeded = null;
                //slotComponent.itemSprite.sprite = null;
            }
        }

        ResetTimer();
        onShipDocked.Invoke();
    }
示例#16
0
    public GameObject SpawnSavedSpaceship(SpaceshipData sData)
    {
        //Debug.Log("Spawning saved spaceship");
        GameObject instantiatedSpaceship = Instantiate(GetSpaceshipTypeByIndex(sData.spaceshipTypeIndex).prefab, new Vector3(sData.position.x, sData.position.y, sData.position.z), Quaternion.identity);

        // Attribute ID to spaceship
        AllySpaceship allyS = instantiatedSpaceship.GetComponent <AllySpaceship>();

        allyS.Initialize();
        allyS.id               = GetAvailableSpaceshipId();
        allyS.spaceshipType    = GetSpaceshipTypeByIndex(sData.spaceshipTypeIndex);
        allyS.level            = sData.level;
        allyS.experiencePoints = sData.experiencePoints;

        AddAlliedSpaceshipToList(instantiatedSpaceship);

        instantiatedSpaceship.transform.SetParent(spaceshipsParent.transform);

        UpdateFleetPointsInfo();

        return(instantiatedSpaceship);
    }
示例#17
0
    public override void Initialize(object _data)
    {
        base.Initialize();

        if (_data != null)
        {
            data = _data as SpaceshipData;
        }
        else
        {
            data = new SpaceshipData(Global.Instance.CONFIGS.spaceships[0].id, 1, null);
        }

        //Skills
        skills.Clear();
        for (int i = 0; i < data.skills.Length; i++)
        {
            var newSkill = new Skill(data.skills[i]);
            skills.Add(newSkill);
        }
        ApplySkills();

        //Equipments
        equipments.Clear();
        if (data.equipments != null)
        {
            for (int i = 0; i < data.equipments.Count; i++)
            {
                var newEquipment = new Equipment(data.equipments[i], 1);
                equipments.Add(newEquipment);
            }
        }

        //Spaceship
        ApplyLevel();
    }
示例#18
0
 public SubsystemBase(SpaceshipController _spaceship)
 {
     data = _spaceship.GetData();
 }
示例#19
0
 internal void load(SpaceshipData spaceshipData)
 {
     load(new Spaceship(spaceshipData));
 }
示例#20
0
 public abstract void ShootBehaviour(Transform transform, SpaceshipData attributes, List <Weapon.Turret> weapon, ref float t);
示例#21
0
 /// <summary>
 /// Inicializa campos que dependem uns dos outros
 /// </summary>
 ///
 /// <param name="spaceshipData">
 /// Os dados do inimigo comum
 /// </param>
 public override void onBuild(SpaceshipData spaceshipData)
 {
     base.onBuild(spaceshipData);
     movementController.switchMovementDirection();
     attackController.normalAttackCoroutine.play(attackController.normalAttack());
 }