Пример #1
0
    public void SetNumEnergy(int number)
    {
        num_usable_energy = 0;

        if (cells != null)
        {
            foreach (GameObject _ in cells)
            {
                Destroy(_);
            }
        }

        cells = new GameObject[number];

        float whole_bar_width = GetComponent <RectTransform>().rect.width;
        float cell_new_width  = whole_bar_width / number;

        float first_pos = -whole_bar_width / 2 + cell_new_width / 2;

        Color fill_color = GameManager.GetInstance().GetFactionMaterial(player.GetFaction()).color;

        for (int i = 0; i < number; i++)
        {
            cells[i] = Instantiate(cell, transform);

            EnergyCell c = cells[i].GetComponent <EnergyCell>();
            c.SetWidth(cell_new_width)
            .SetAnchoredX(first_pos + cell_new_width * i)
            .SetFillColor(fill_color);
        }
    }
Пример #2
0
        public bool CreateExperiment(Experiment experiment, List <EnergyCellExtend> cellExtends, List <AtomExtend> atomExtends,
                                     out List <EnergyCellExtend> newCells, out List <AtomExtend> newAtoms)
        {
            List <Tuple <EnergyCellExtend, EnergyCell> > cellPairs = new List <Tuple <EnergyCellExtend, EnergyCell> >();

            List <EnergyCell> energyCells = new List <EnergyCell>();

            cellExtends.ForEach(m =>
            {
                var energyCell   = new EnergyCell();
                energyCell.CellX = m.CellX;
                energyCell.CellY = m.CellY;
                energyCell.Order = m.Order;
                m.Experiment     = experiment;
                energyCells.Add(energyCell);

                cellPairs.Add(new Tuple <EnergyCellExtend, EnergyCell>(m, energyCell));
            });



            List <Tuple <AtomExtend, Atom> > atomPairs = new List <Tuple <AtomExtend, Atom> >();

            List <Atom> atoms = new List <Atom>();

            atomExtends.ForEach(m =>
            {
                var atom              = new Atom();
                atom.VolumeRadius     = m.VolumeRadius;
                atom.AttractionRadius = m.AttractionRadius;
                atom.AttractionForce  = m.AttractionForce;
                atom.Order            = m.Order;
                atom.Experiment       = experiment;
                atoms.Add(atom);

                atomPairs.Add(new Tuple <AtomExtend, Atom>(m, atom));
            });



            experiment.StartCells   = energyCells.Count;
            experiment.StartHotPots = cellExtends.Count(m => m.IsHotPot);
            experiment.StartAtoms   = atoms.Count;

            experiment.EnergyCells = energyCells;
            experiment.Atoms       = atoms;

            DbContext.Experiments.Add(experiment);
            DbContext.SaveChanges();

            Experiment = experiment;

            cellPairs.ForEach(m =>
            {
                m.Item1.EnergyCellID = m.Item2.EnergyCellID;
                m.Item1.ExperimentID = m.Item2.ExperimentID;
            });
            newCells = cellPairs.Select(m => m.Item1).ToList();


            atomPairs.ForEach(m =>
            {
                m.Item1.AtomID       = m.Item2.AtomID;
                m.Item1.ExperimentID = m.Item2.ExperimentID;
            });
            newAtoms = atomPairs.Select(m => m.Item1).ToList();

            return(true);
        }
Пример #3
0
        public override bool FireEvent(Event E)
        {
            if (E.ID == "BeforeApplyDamage")
            {
                Damage parameter = E.GetParameter("Damage") as Damage;
                if (!(parameter.HasAttribute("Electric") || parameter.HasAttribute("Shock") || parameter.HasAttribute("Lightning") || parameter.HasAttribute("Electricity")))
                {
                    return(true);
                }

                double ReductionDouble = (double)parameter.Amount * GetPercentageResist(this.Level);
                int    Reduction       = (int)Math.Floor(ReductionDouble);
                if (ReductionDouble - (double)Reduction >= Stat.Rnd.NextDouble())
                {
                    Reduction += 1;
                }
                if (Reduction > 0 && this.ParentObject.IsPlayer())
                {
                    MessageQueue.AddPlayerMessage("Your scales absorb " + Reduction.ToString() + " damage from the electricity.");
                }
                parameter.Amount = Math.Max(0, parameter.Amount - Reduction);
                return(false);
            }
            if (E.ID == "EndTurn" && this.ChargeCellsActivatedAbility != null && this.ChargeCellsActivatedAbility.ToggleState)
            {
                foreach (GameObject EquippedObject in this.ParentObject.GetPart <Body>().GetEquippedObjects())
                {
                    if (EquippedObject == null)
                    {
                        continue;
                    }

                    EnergyCell Cell = null;
                    if (EquippedObject != null && EquippedObject.HasPart("EnergyCell"))
                    {
                        Cell = EquippedObject.GetPart <EnergyCell>();
                    }
                    else if (EquippedObject.HasPart("EnergyCellSocket"))
                    {
                        EnergyCellSocket Socket = this.ParentObject.GetPart <EnergyCellSocket>();
                        if (Socket.Cell != null && Socket.Cell.HasPart("EnergyCell"))
                        {
                            Cell = Socket.Cell.GetPart <EnergyCell>();
                        }
                    }

                    if (Cell != null && Cell.CanBeRecharged() && Cell.GetRechargeAmount() > 0)
                    {
                        // Cells have varying degrees of charge rates so we need to
                        int RechargedAmount = ConsumeCharge(Math.Min(Cell.GetRechargeAmount(), Cell.ChargeRate));
                        if (RechargedAmount == 0) // hungry....
                        {
                            if (this.ParentObject.IsPlayer())
                            {
                                MessageQueue.AddPlayerMessage("You're too hungry to muster any more energy...");
                            }
                            this.ChargeCellsActivatedAbility.ToggleState = false;
                            break;
                        }
                        else
                        {
                            Cell.AddCharge(RechargedAmount);
                        }
                    }
                }
            }
            return(base.FireEvent(E));
        }