コード例 #1
0
    public override void Initialize(LDBlock _data)
    {
        GridPos            = (Vector2Int)Grid.WorldToCell(transform.position);
        transform.position = Grid.CellToWorld((Vector3Int)GridPos);
        Grid.setOccupied((Vector3Int)GridPos, true);

        Animator      = GetComponentInChildren <Animator>();
        AbilitySystem = new AbilitySystem(this);

        CharacterDataTemplate Data = CharacterDataTemplate.Load();

        Data.GetMonsterStartingAttributes(Role)
        .ForEach(Entry => AbilitySystem.RegisterAttribute(Entry.Attribute, Entry.Value));
        Data.GetMonsterAbilities(Role)
        .ForEach(Ability => AbilitySystem.GrantAbility(Ability));
        Data.GetMonsterStartingEffects(Role)
        .ForEach(Effect => AbilitySystem.TryApplyEffectToSelf(Effect));


        AbilitySystem.RegisterOnAttributeChanged(Attribute.Health, OnDamageTaken);
        CurrentHealth = AbilitySystem.GetAttributeValue(Attribute.Health).Value;

        AbilitySystem.RegisterOnAttributeChanged(Attribute.MaxHealth, UpdateMaxHealth);
        MaxHealth = AbilitySystem.GetAttributeValue(Attribute.MaxHealth).Value;

        AbilitySystem
        .GetGrantedAbilityTypes()
        .ForEach(Ability =>
        {
            if (!Ability.Is(TypeTag.MoveAbility))
            {
                MainAbility = Ability;
            }
        });
    }
コード例 #2
0
ファイル: PlayableAgent.cs プロジェクト: molvin/LD48
    public override void Initialize(LDBlock data)
    {
        bool found = false;
        LDCharacter OwningCharacter = new LDCharacter();
        foreach (LDCharacter Character in data.characters)
        {
            if (Character.role == (byte)Role)
            {
                OwningCharacter = Character;
                found = true;
            }
        }
        if(!found)
        {
            DestroyImmediate(gameObject);
            return;
        }

        GridPos = (Vector2Int)GameStateManager.Instance.GetGridManager().WorldToCell(transform.position);
        transform.position = GameStateManager.Instance.GetGridManager().CellToWorld((Vector3Int)GridPos);
        GameStateManager.Instance.GetGridManager().setOccupied((Vector3Int)GridPos, true);

        Animator = GetComponentInChildren<Animator>();
        AbilitySystem = new AbilitySystem(this);
        Name = OwningCharacter.name;
        Color = (CharacterColor)OwningCharacter.color;
        if (OwningCharacter.timeLine != null)
        {
            TimeLine = OwningCharacter.timeLine.ToList();
        }
        else
        {
            TimeLine = new List<LDInputFrame>();
        }

        CharacterDataTemplate Data = CharacterDataTemplate.Load();

        if (OwningCharacter.attributes == null || OwningCharacter.attributes.Length == 0)
        {
            // NOTE: First time, Playing from start!
            Data.GetStartingAttributes(Role)
                .ForEach(Entry => AbilitySystem.RegisterAttribute(Entry.Attribute, Entry.Value));
        }
        else
        {
            AbilitySystem.RegisterLDAttributes(OwningCharacter.attributes);
        }

        Data.GetAbilities(Role)
            .ForEach(Ability => AbilitySystem.GrantAbility(Ability));

        Data.GetStartingEffects(Role)
            .ForEach(Effect => AbilitySystem.TryApplyEffectToSelf(Effect));

        AbilitySystem.RegisterOnAttributeChanged(Attribute.Health, OnDamageTaken);
        CurrentHealth = AbilitySystem.GetAttributeValue(Attribute.Health).Value;

        AbilitySystem.RegisterOnAttributeChanged(Attribute.MaxHealth, UpdateMaxHealth);
        MaxHealth = AbilitySystem.GetAttributeValue(Attribute.MaxHealth).Value;
    }
コード例 #3
0
    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(this);
        }
        else
        {
            Destroy(gameObject);
            return;
        }
        LDConversionTable LDConversionTable = LDConversionTable.Load();

        m_DeathInputFrame = new LDInputFrame {
            action = LDConversionTable.GameplayTagToLDID(TypeTag.DeathAction), cell = 0
        };

        m_ServerTimeLine = new Server().RequestTimeLine();

        if (m_ServerTimeLine.timeLine == null || m_ServerTimeLine.timeLine.Length <= 0)
        {
            m_ServerTimeLine.timeLine = new LDBlock[0];
            m_BranchingIndex          = 0;
            m_CurrentBlock.mods       = new LDAttribute[0];

            m_CurrentBlock.branches                  = new int[0];
            m_CurrentBlock.characters                = new LDCharacter[3];
            m_CurrentBlock.characters[0].role        = (byte)CharacterRole.Assassin;
            m_CurrentBlock.characters[0].timeLine    = new LDInputFrame[1];
            m_CurrentBlock.characters[0].timeLine[0] = m_DeathInputFrame;
            m_CurrentBlock.characters[0].name        = "Ezio";
            m_CurrentBlock.characters[0].attributes  = new LDAttribute[0];

            m_CurrentBlock.characters[1].role        = (byte)CharacterRole.Barbarian;
            m_CurrentBlock.characters[1].timeLine    = new LDInputFrame[1];
            m_CurrentBlock.characters[1].timeLine[0] = m_DeathInputFrame;
            m_CurrentBlock.characters[1].name        = "Barb";
            m_CurrentBlock.characters[1].attributes  = new LDAttribute[0];

            m_CurrentBlock.characters[2].role        = (byte)CharacterRole.Necromancer;
            m_CurrentBlock.characters[2].timeLine    = new LDInputFrame[1];
            m_CurrentBlock.characters[2].timeLine[0] = m_DeathInputFrame;
            m_CurrentBlock.characters[2].name        = "Bob";
            m_CurrentBlock.characters[2].attributes  = new LDAttribute[0];
        }
        else
        {
            m_CurrentBlock = m_ServerTimeLine.timeLine[0];
        }
    }
コード例 #4
0
    public IEnumerator LoadScene()
    {
        m_IsLoadingScene = true;
        LDBlock next_block = TimelineHolder.Instance.GenerateNextRelevantBlock();

        SceneManager.LoadScene(next_block.level);

        yield return(null);

        Ticker.currentBlock = TimelineHolder.Instance.GetCurrentBlock();
        Ticker.Instance.Initialize();
        Ticker.Instance.TickToNextCheckpoint(false);
        m_IsLoadingScene = false;
    }
コード例 #5
0
    public LDBlock GenerateNextRelevantBlock()
    {
        LDBlock temp_block = new LDBlock();


        //Select the first branch
        if (m_CurrentBlock.branches.Length > 0)
        {
            //Maybe chosie
            temp_block = m_ServerTimeLine.timeLine[m_CurrentBlock.branches[0]];
        }
        else //If there are no branches then we create a new one
        {
            temp_block.level      = SceenIndex < 0 ? (ushort)Random.Range(2, SceneManager.sceneCountInBuildSettings) : (ushort)SceenIndex;
            temp_block.mods       = m_CurrentBlock.mods;
            temp_block.characters = m_CurrentBlock.characters;

            PlayableAgent[] player_agents = FindObjectsOfType <PlayableAgent>(true);
            //Jag vet inte vad den här koden gör!?! x 100 /Daniel 2021
            for (int i = 0; i < m_CurrentBlock.characters.Length; i++)
            {
                LDCharacter character = m_CurrentBlock.characters[i];

                foreach (PlayableAgent player in player_agents)
                {
                    if ((byte)player.Role == character.role)
                    {
                        LDCharacter current_character = player.ToLDCharacter();
                        current_character.timeLine    = new LDInputFrame[1];
                        current_character.timeLine[0] = m_DeathInputFrame; //TODO: Maybe not dead
                        temp_block.characters[i]      = current_character;
                    }
                }
            }

            temp_block.branches = new int[0];
        }

        m_CurrentBlock = temp_block;

        return(m_CurrentBlock);
    }
コード例 #6
0
        static WritableSystem()
        {
            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();

            //Scan trough assembly and find all methods with a write or read attribute in the domain.
            AddAllWritableFieldTypes(assemblies);

            //Get all Writables and IMessage types in the current domain
            List <Type> WritableTypes = new List <Type>();

            foreach (Assembly a in assemblies)
            {
                WritableTypes.AddRange(a.GetTypes().Where(x => TypeIsWritable(x)));
            }

            //Add each writable type as it's own writabletype!
            foreach (Type t in WritableTypes)
            {
                AddSuportedType(t, (s, o) => Write(s, o), (Func <Stream, object>)_readReadInternal.MakeGenericMethod(t).CreateDelegate(typeof(Func <Stream, object>)));
            }

            //Do calculations for field members
            foreach (Type t in WritableTypes)
            {
                AddWritable(t);
            }


            MemoryStream mem = new MemoryStream();

            //Int
            int[] inttemp = new int[] { 0 };
            WriteArray <int>(mem, inttemp);
            mem.Seek(0, SeekOrigin.Begin);
            ReadArray <int>(mem);
            mem.Seek(4, SeekOrigin.Begin);
            ReadInternal <int>(mem);

            //LDBLock
            LDBlock[] temp = new LDBlock[] {
                new LDBlock {
                    level      = 0,
                    branches   = new int[] { 1 },
                    characters = new LDCharacter[] {},
                    mods       = new LDAttribute[] {}
                }
            };
            mem.Seek(0, SeekOrigin.Begin);
            WriteArray <LDBlock>(mem, temp);
            mem.Seek(0, SeekOrigin.Begin);
            ReadArray <LDBlock>(mem);
            mem.Seek(4, SeekOrigin.Begin);
            ReadInternal <LDBlock>(mem);
            //LDAttribute
            LDAttribute[] temp1 = new LDAttribute[] {
                new LDAttribute {
                    type  = 0,
                    value = 0
                }
            };
            mem.Seek(0, SeekOrigin.Begin);
            WriteArray <LDAttribute>(mem, temp1);
            mem.Seek(0, SeekOrigin.Begin);
            ReadArray <LDAttribute>(mem);
            mem.Seek(4, SeekOrigin.Begin);
            ReadInternal <LDAttribute>(mem);
            //LDInputFrame
            LDInputFrame[] temp2 = new LDInputFrame[] {
                new LDInputFrame {
                    action = 0,
                    cell   = 0
                }
            };
            mem.Seek(0, SeekOrigin.Begin);
            WriteArray <LDInputFrame>(mem, temp2);
            mem.Seek(0, SeekOrigin.Begin);
            ReadArray <LDInputFrame>(mem);
            mem.Seek(4, SeekOrigin.Begin);
            ReadInternal <LDInputFrame>(mem);
            //LDCharacter
            LDCharacter[] temp3 = new LDCharacter[] {
                new LDCharacter {
                    attributes = temp1,
                    color      = 0,
                    name       = "",
                    role       = 0,
                    timeLine   = temp2
                }
            };
            mem.Seek(0, SeekOrigin.Begin);
            WriteArray <LDCharacter>(mem, temp3);
            mem.Seek(0, SeekOrigin.Begin);
            ReadArray <LDCharacter>(mem);
            mem.Seek(4, SeekOrigin.Begin);
            ReadInternal <LDCharacter>(mem);
        }
コード例 #7
0
        private void Start()
        {
            LDBlock block = new LDBlock
            {
                characters = new LDCharacter[]
                {
                    // Assassin
                    new LDCharacter
                    {
                        name       = "Lola the Assassin",
                        color      = 2,
                        role       = 1,
                        attributes = new LDAttribute[]
                        {
                            new LDAttribute {
                                type = 0, value = 80
                            },
                            new LDAttribute {
                                type = 1, value = 100
                            },
                            new LDAttribute {
                                type = 2, value = 10
                            },
                            new LDAttribute {
                                type = 3, value = 50
                            },
                            new LDAttribute {
                                type = 4, value = 4
                            },
                        },
                        timeLine = new LDInputFrame[]
                        {
                            new LDInputFrame {
                                action = 0, cell = 4,
                            },
                            new LDInputFrame {
                                action = 0, cell = 14,
                            },
                            new LDInputFrame {
                                action = 0, cell = 17,
                            },
                        },
                    },
                    // Barbarian
                    new LDCharacter
                    {
                        name       = "Beny the Barbarian",
                        color      = 3,
                        role       = 0,
                        attributes = new LDAttribute[]
                        {
                            new LDAttribute {
                                type = 0, value = 80
                            },
                            new LDAttribute {
                                type = 1, value = 100
                            },
                            new LDAttribute {
                                type = 2, value = 10
                            },
                            new LDAttribute {
                                type = 3, value = 50
                            },
                            new LDAttribute {
                                type = 4, value = 2
                            },
                        },
                        timeLine = new LDInputFrame[]
                        {
                            new LDInputFrame {
                                action = 0, cell = 16,
                            },
                            new LDInputFrame {
                                action = 0, cell = 30,
                            },
                            new LDInputFrame {
                                action = 0, cell = 32,
                            },
                        },
                    },
                    // Barbarian
                    new LDCharacter
                    {
                        name       = "Ninni the Necromancer",
                        color      = 1,
                        role       = 2,
                        attributes = new LDAttribute[]
                        {
                            new LDAttribute {
                                type = 0, value = 80
                            },
                            new LDAttribute {
                                type = 1, value = 100
                            },
                            new LDAttribute {
                                type = 2, value = 10
                            },
                            new LDAttribute {
                                type = 3, value = 50
                            },
                            new LDAttribute {
                                type = 4, value = 1
                            },
                        },
                        timeLine = new LDInputFrame[]
                        {
                            new LDInputFrame {
                                action = 0, cell = 12,
                            },
                            new LDInputFrame {
                                action = 0, cell = 14,
                            },
                            new LDInputFrame {
                                action = 0, cell = 13,
                            },
                        },
                    },
                },
            };

            Ticker.currentBlock = block;
            Ticker.Initialize();
        }
コード例 #8
0
ファイル: TickAgent.cs プロジェクト: molvin/LD48
 public abstract void Initialize(LDBlock data);