/// <summary> /// Determine whether a user can execute a <see cref="StatePath"/> in general. /// The user must alse have read and write access rights to a stateful object in order to be allowed /// state path execution. /// </summary> /// <param name="user">The user.</param> /// <param name="statePath">The state path to execute.</param> /// <param name="segregation">Optional segregation where the stateful object may belong.</param> public bool CanUserExecuteStatePath(U user, StatePath statePath, Segregation <U> segregation = null) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (statePath == null) { throw new ArgumentNullException(nameof(statePath)); } var rolesAccessRight = GetRolesAccessRight(user); if (rolesAccessRight.SupportsStatePath(statePath)) { return(true); } if (segregation != null) { AccessRight dispositionsAccessRight = GetDispositionsAccessRight(user, segregation); return(dispositionsAccessRight.SupportsStatePath(statePath)); } return(false); }
public void State_Test() { var path = new StatePath(); path.Parts.Add("dummy_address"); var mockProvider = new Mock <IStateProvider>(); var mockContext = new Mock <ISmartContractBridgeContext>(); mockContext.SetupGet(o => o.StateProvider).Returns(mockProvider.Object); mockContext.SetupGet(o => o.Self).Returns(SampleAddress.AddressList[0]); var state = new MockContractState { Path = path, Context = new CSharpSmartContractContext(mockContext.Object) }; // Initial default value AssertDefault(state); // Set values SetValues(state); AssertValues(state); // Get changes var changes = state.GetChanges(); changes.Reads.Count.ShouldBeGreaterThan(0); changes.Writes.Count.ShouldBeGreaterThan(0); // Clear values state.Clear(); AssertDefault(state); }
/// <summary> /// 添加状态 /// </summary> /// <param name="_s">S.</param> /// <param name="_enter">Enter.</param> /// <param name="_update">Update.</param> /// <param name="_leave">Leave.</param> public void AddState(StatePath _s, VoidDelegate _enter = null, VoidDelegateFloat _update = null, VoidDelegate _leave = null) { if (!allState.ContainsKey(_s.stateName)) { _s.BindStateMethod(_enter, _update, _leave); allState.Add(_s.stateName, _s); } }
public void GoToFishingPath() { FeedingPath.Target = null; FishingPath.Target = Fish.transform; FeedingPath.Stop(); FishingPath.Play(); statePath = StatePath.Fishing; }
public static string ToStateKey(this StatePath statePath, Address address) { return(new ScopedStatePath() { Address = address, Path = statePath }.ToStateKey()); }
private StatePath GetStatePathFor(string key) { var sp = new StatePath(); sp.Path.AddRange(Path); sp.Path.Add(ByteString.CopyFromUtf8(key)); return(sp); }
public void IrAMinar() { if (statePath == StatePath.Nulo) { CheckNodeActual(transform.position); if (objetivoTrabajo != null && objetivoTrabajo.GetComponent <GameElement>() != null) { nodoFinal = objetivoTrabajo.GetComponent <GameElement>().GetMyNode(); if (nodoFinal != null) { if (nodoFinal.IsObstacle == true) { nodoFinalObstaculo = true; nodoFinal.IsObstacle = false; } //Debug.Log("ENTRE AL PATH"); CheckPath(); //Debug.Log(path.Count); statePath = StatePath.EnUso; } } } if (nodoFinal != null) { Vector3 diff; if (path.Count > 0) { if (i < path.Count) { //Debug.Log("Sub indice:"+i); Vector3 point = path[i].transform.position; point.y = transform.position.y; transform.LookAt(point); transform.position += transform.forward * speed * Time.deltaTime; diff = point - this.transform.position; if (diff.magnitude < 0.5f) { i++; } } else { FinishPath(); fsm.SendEvent((int)EventosAldeano.Stop); trabajo = " "; } } } if (trabajo == "Llevar Oro") { fsm.SendEvent((int)EventosAldeano.ClickInHouse); } if (trabajo == "Mover Aldeano") { fsm.SendEvent((int)EventosAldeano.ClickInMap); } }
void setState(StatePath _sp) { if (_state.IsState(_sp)) { return; } _state.SetState(_sp); }
public void State_Test() { var path = new StatePath(); path.Parts.Add("dummy_address"); var mockProvider = new Mock <IStateProvider>(); var mockContext = new Mock <ISmartContractBridgeContext>(); mockContext.SetupGet(o => o.StateProvider).Returns(mockProvider.Object); mockContext.SetupGet(o => o.Self).Returns(SampleAddress.AddressList[0]); var state = new MockContractState { Path = path, Context = new CSharpSmartContractContext(mockContext.Object) }; // Initial default value AssertDefault(state); // Set values SetValues(state); AssertValues(state); // Get changes var changes = state.GetChanges(); changes.Reads.Count.ShouldBeGreaterThan(0); changes.Writes.Count.ShouldBeGreaterThan(0); state.MappedState[SampleAddress.AddressList[0]][SampleAddress.AddressList[1]] = "test"; state.MappedState[SampleAddress.AddressList[0]][SampleAddress.AddressList[2]] = "test2"; state.MappedState[SampleAddress.AddressList[3]][SampleAddress.AddressList[4]] = "test3"; state.MappedState[SampleAddress.AddressList[0]].Remove(SampleAddress.AddressList[1]); state.MappedState[SampleAddress.AddressList[3]].Remove(SampleAddress.AddressList[4]); changes = state.GetChanges(); var key = string.Join("/", SampleAddress.AddressList[0].GetFormatted(), "dummy_address", "MappedState", SampleAddress.AddressList[0].ToString(), SampleAddress.AddressList[1].ToString() ); changes.Deletes.TryGetValue(key, out _).ShouldBeTrue(); key = string.Join(",", SampleAddress.AddressList[0].GetFormatted(), "dummy_address", "MappedState", SampleAddress.AddressList[0].ToString(), SampleAddress.AddressList[2].ToString()); changes.Deletes.TryGetValue(key, out _).ShouldBeFalse(); key = string.Join("/", SampleAddress.AddressList[0].GetFormatted(), "dummy_address", "MappedState", SampleAddress.AddressList[3].ToString(), SampleAddress.AddressList[4].ToString()); changes.Deletes.TryGetValue(key, out _).ShouldBeTrue(); key = string.Join("/", SampleAddress.AddressList[0].GetFormatted(), "dummy_address", "MappedState", SampleAddress.AddressList[4].ToString(), SampleAddress.AddressList[5].ToString()); changes.Deletes.TryGetValue(key, out _).ShouldBeFalse(); // Clear values state.Clear(); AssertDefault(state); }
/// <summary> /// 是否是当前状态 /// </summary> /// <returns><c>true</c> if this instance is state the specified _s; otherwise, <c>false</c>.</returns> /// <param name="_s">S.</param> public bool IsState(StatePath _s) { if (currentState.stateName == _s.stateName) { return(true); } return(false); }
private void Start() { if (GameManager.instanceGameManager != null) { gm = GameManager.instanceGameManager; } nodoFinalObstaculo = false; nodoInicialObstaculo = false; statePath = StatePath.Nulo; }
public void FishingPathToMainPath() { setDirectFishing = false; MainPath.Target = Fish.transform; FishingPath.Target = null; FishingPath.Stop(); MainPath.Play(); statePath = StatePath.Fish; fishingManager.SetReurn(); }
public async Task <byte[]> GetAsync(StatePath path) { var scoped = new ScopedStatePath() { Address = ContractAddress, Path = path }; var byteString = await HostSmartContractBridgeContext.GetStateAsync(scoped.ToStateKey()); return(byteString?.ToByteArray()); }
public void BackMainPath() { setDirectFeed = false; setDirectFishing = false; BackFeedingPath.Waypoints[0].Position = new Vector3(Fish.transform.position.x, Fish.transform.position.y, Fish.transform.position.z); FeedingPath.Target = null; BackFeedingPath.Target = Fish.transform; FeedingPath.Stop(); BackFeedingPath.Play(); statePath = StatePath.BackFeeding; }
public void SetFishng() { FeedingPath.velocityBias = Random.Range(0.15f, 0.8f); setDirectFishing = true; FeedingPath.Waypoints[0].Position = new Vector3(Fish.transform.position.x, Fish.transform.position.y, Fish.transform.position.z); MainPath.Target = null; FeedingPath.Target = Fish.transform; MainPath.Stop(); FeedingPath.Play(); statePath = StatePath.Feed; }
public void SetDefaultState() { Fish.GetComponent <Animation>().PlayQueued("Moving", QueueMode.PlayNow); statePath = StatePath.Fish; MainPath.Target = Fish.transform; BackFeedingPath.Target = null; BackFeedingPath.Stop(); FeedingPath.Target = null; FeedingPath.Stop(); SetDefaultColor(); MainPath.Play(); }
public byte[] Get(StatePath path) { var scoped = new ScopedStatePath() { Address = ContractAddress, Path = path }; var byteString = AsyncHelper.RunSync(() => HostSmartContractBridgeContext.GetStateAsync(scoped.ToStateKey())); return(byteString?.ToByteArray()); }
public void FinishPath() { i = 0; statePath = StatePath.Nulo; if (nodoFinalObstaculo) { nodoFinal.IsObstacle = true; nodoFinalObstaculo = false; } gm.pathGenerator.CleanNodes(); path.Clear(); }
public async Task Test() { var db = new InMemoryDatabase(); var chainId = Hash.FromString("chain1"); var address = Address.FromRawBytes(Hash.FromString("contract1").ToByteArray()); var root = DataProvider.GetRootDataProvider(chainId, address); root.StateStore = new StateStore(db); var s = "test"; var sb = Encoding.UTF8.GetBytes(s); var statePath = new StatePath() { Path = { ByteString.CopyFrom(address.DumpByteArray()), ByteString.CopyFromUtf8(s) } }; await root.SetAsync(s, sb); // Value correctly set var retrievedChanges = root.GetChanges(); Assert.Equal(1, retrievedChanges.Count); var bytes = retrievedChanges[statePath].CurrentValue.ToByteArray(); Assert.Equal(s, Encoding.UTF8.GetString(bytes)); // Commit changes to store var toCommit = retrievedChanges.ToDictionary(kv => kv.Key, kv => kv.Value.CurrentValue.ToByteArray()); await root.StateStore.PipelineSetDataAsync(toCommit); // Setting the same value again in another DataProvider, no change will be returned var root2 = DataProvider.GetRootDataProvider(chainId, address); root2.StateStore = new StateStore(db); await root2.SetAsync(s, sb); var changes2 = root2.GetChanges(); Assert.Equal(0, changes2.Count); // Test path var sub = root.GetChild("sub"); await sub.SetAsync("dummy", new byte[] { 0x01 }); var subPath = sub.GetChanges().Keys.First(); var path = new RepeatedField <ByteString> { ByteString.CopyFrom(address.DumpByteArray()), ByteString.Empty, ByteString.CopyFromUtf8("sub"), ByteString.CopyFromUtf8("dummy") }; Assert.Equal(subPath.Path, path); }
/// <summary> /// 设置为上个状态 /// </summary> public void ToLastState() { if (currentState == lastState) { return; } currentState.ExecuteLeave(); lastState.ExecuteEnter(); StatePath cachedCurrentState = currentState; currentState = lastState; lastState = cachedCurrentState; stateTime = 0; }
/// <summary> /// Create. /// </summary> /// <param name="statePath">The state path whose execution is denied.</param> /// <param name="statefulObject">The stateful object against which the state path execution was denied.</param> /// <param name="message">The message of the exception.</param> public StatePathAccessDeniedException(StatePath statePath, IEntityWithID <long> statefulObject, string message) : base(message) { if (statePath == null) { throw new ArgumentNullException(nameof(statePath)); } if (statefulObject == null) { throw new ArgumentNullException(nameof(statefulObject)); } this.StatePathCodeName = statePath.CodeName; this.StatefulObjectID = statefulObject.ID; }
public void SetMainPath() { Fish.GetComponent <Animation>().PlayQueued("Moving", QueueMode.PlayNow); statePath = StatePath.Fish; MainPath.Target = Fish.transform; BackFeedingPath.Target = null; BackFeedingPath.Stop(); MainPath.Play(); if (feedingManager.stateFeeding == FeedingManager.StateFeed.Feeding) { feedingManager.SetReurn(); } if (fishingManager.stateFishing == FishngManager.StateFishing.Fishing) { fishingManager.SetReurn(); } }
public void ReadOnlyState_Test() { var path = new StatePath(); path.Parts.Add("dummy_address"); var mockProvider = new Mock <IStateProvider>(); var mockContext = new Mock <ISmartContractBridgeContext>(); mockContext.SetupGet(o => o.StateProvider).Returns(mockProvider.Object); mockContext.SetupGet(o => o.Self).Returns(SampleAddress.AddressList[0]); var readOnlyState = new ReadonlyState <int> { Path = path, Context = new CSharpSmartContractContext(mockContext.Object) }; readOnlyState.Value.ShouldBe(default);
/// <summary> /// 设置状态 /// </summary> /// <param name="_s">S.</param> public void SetState(StatePath _s) { if (!allState.ContainsKey(_s.stateName) || currentState == _s) { return; } if (currentState != null) { currentState.ExecuteLeave(); } lastState = currentState; currentState = _s; stateTime = 0; currentState.ExecuteEnter(); }
public void LLevarOro() { //Debug.Log("Llevando el oro"); //DEBERIA FIJARSE CUAL ES EL ALMACEN DE ORO O CENTRO URBANO MAS CERCANO BuscarAlmacenMasCercano(); if (depositoMasCercano != null) { if (statePath == StatePath.Nulo) { //gm.pathGenerator.CleanNodes(); CheckNodeActual(transform.position); nodoFinal = depositoMasCercano.gameObject.GetComponent <GameElement>().GetMyNode(); if (nodoFinal.IsObstacle == true) { nodoFinalObstaculo = true; nodoFinal.IsObstacle = false; } CheckPath(); statePath = StatePath.EnUso; } Vector3 diff; if (path.Count > 0) { if (i < path.Count) { Vector3 point = path[i].transform.position; point.y = transform.position.y; transform.LookAt(point); transform.position += transform.forward * speed * Time.deltaTime; diff = point - this.transform.position; if (diff.magnitude < 0.5f) { i++; } } } } }
public byte[] Get(StatePath path) { var scoped = new ScopedStatePath() { Address = ContractAddress, Path = path }; if (Cache.TryGetValue(scoped, out var value)) { return(value); } var bytes = _inner.Get(path); Cache[scoped] = bytes; return(bytes); }
/// <summary> /// Create. /// </summary> /// <param name="stateful">The stateful object to execute the path on.</param> /// <param name="statePath">The state path to execute.</param> /// <param name="executionMode">The path execution model.</param> public StatefulObjectExecutionModel(SO stateful, StatePath statePath, StatePathExecutionModel executionMode) { if (stateful == null) { throw new ArgumentNullException(nameof(stateful)); } if (statePath == null) { throw new ArgumentNullException(nameof(statePath)); } if (executionMode == null) { throw new ArgumentNullException(nameof(executionMode)); } this.Stateful = stateful; this.StatePath = statePath; this.ExecutionModel = executionMode; }
public async Task <byte[]> GetAsync(StatePath path) { var scoped = new ScopedStatePath() { Address = ContractAddress, Path = path }; if (Cache.TryGetValue(scoped, out var value)) { return(value); } var bytes = await _inner.GetAsync(path); Cache[scoped] = bytes; return(bytes); }
public async Task <byte[]> GetAsync(StatePath path) { try { if (path == null) { throw new ArgumentNullException(nameof(path)); } var key = GetKey(path); var res = await _keyValueDatabase.GetAsync(_dbName, key); // return res ?? new byte[0]; return(res); } catch (Exception e) { Console.WriteLine(e); throw; } }
private void Awake() { nodoFinalObstaculo = false; nodoInicialObstaculo = false; statePath = StatePath.Nulo; Depositos = new List <GameObject>(); if (GameManager.instanceGameManager != null) { gm = GameManager.instanceGameManager; } // Aca defino las relaciones de estado y le hago el new al objeto FSM fsm = new FSM((int)EstadosAldeano.Count, (int)EventosAldeano.Count, (int)EstadosAldeano.Idle); //minero fsm.SetRelations((int)EstadosAldeano.Idle, (int)EstadosAldeano.IrAMinar, (int)EventosAldeano.ClickInMine); fsm.SetRelations((int)EstadosAldeano.IrAMinar, (int)EstadosAldeano.Minando, (int)EventosAldeano.CollisionMine); fsm.SetRelations((int)EstadosAldeano.IrAMinar, (int)EstadosAldeano.CancelarAccion, (int)EventosAldeano.Stop); fsm.SetRelations((int)EstadosAldeano.Minando, (int)EstadosAldeano.LLevarOro, (int)EventosAldeano.FullCapasity); fsm.SetRelations((int)EstadosAldeano.Minando, (int)EstadosAldeano.IrAMinar, (int)EventosAldeano.ClickInMine); fsm.SetRelations((int)EstadosAldeano.Minando, (int)EstadosAldeano.CancelarAccion, (int)EventosAldeano.Stop); fsm.SetRelations((int)EstadosAldeano.LLevarOro, (int)EstadosAldeano.DepositarOro, (int)EventosAldeano.CollisionHouse); fsm.SetRelations((int)EstadosAldeano.LLevarOro, (int)EstadosAldeano.CancelarAccion, (int)EventosAldeano.Stop); fsm.SetRelations((int)EstadosAldeano.DepositarOro, (int)EstadosAldeano.Idle, (int)EventosAldeano.Stop); fsm.SetRelations((int)EstadosAldeano.DepositarOro, (int)EstadosAldeano.IrAMinar, (int)EventosAldeano.ClickInMine); fsm.SetRelations((int)EstadosAldeano.CancelarAccion, (int)EstadosAldeano.Idle, (int)EventosAldeano.Stop); fsm.SetRelations((int)EstadosAldeano.Idle, (int)EstadosAldeano.LLevarOro, (int)EventosAldeano.ClickInHouse); fsm.SetRelations((int)EstadosAldeano.IrAMinar, (int)EstadosAldeano.LLevarOro, (int)EventosAldeano.ClickInHouse); fsm.SetRelations((int)EstadosAldeano.Minando, (int)EstadosAldeano.LLevarOro, (int)EventosAldeano.ClickInHouse); //movimiento fsm.SetRelations((int)EstadosAldeano.Idle, (int)EstadosAldeano.MoverAldeano, (int)EventosAldeano.ClickInMap); fsm.SetRelations((int)EstadosAldeano.IrAMinar, (int)EstadosAldeano.MoverAldeano, (int)EventosAldeano.ClickInMap); fsm.SetRelations((int)EstadosAldeano.Minando, (int)EstadosAldeano.MoverAldeano, (int)EventosAldeano.ClickInMap); fsm.SetRelations((int)EstadosAldeano.MoverAldeano, (int)EstadosAldeano.Idle, (int)EventosAldeano.Stop); fsm.SetRelations((int)EstadosAldeano.MoverAldeano, (int)EstadosAldeano.LLevarOro, (int)EventosAldeano.ClickInHouse); fsm.SetRelations((int)EstadosAldeano.MoverAldeano, (int)EstadosAldeano.IrAMinar, (int)EventosAldeano.ClickInMine); normalSpeed = speed; waterSpeed = normalSpeed / 2; }