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; }
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); }
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); }
public LDCharacter AppendTimeline(LDCharacter character) { character.timeLine = TimeLine.ToArray(); return character; }